yiisoft/yii2 · error · InvalidConfigException

Unknown attribute: $attribute

Error message

Unknown attribute: $attribute

What it means

Error "Unknown attribute: $attribute" thrown in yiisoft/yii2.

Source

Thrown at framework/data/Sort.php:452

        if ($absolute) {
            return $urlManager->createAbsoluteUrl($params);
        }

        return $urlManager->createUrl($params);
    }

    /**
     * Creates the sort variable for the specified attribute.
     * The newly created sort variable can be used to create a URL that will lead to
     * sorting by the specified attribute.
     * @param string $attribute the attribute name
     * @return string the value of the sort variable
     * @throws InvalidConfigException if the specified attribute is not defined in [[attributes]]
     */
    public function createSortParam($attribute)
    {
        if (!isset($this->attributes[$attribute])) {
            throw new InvalidConfigException("Unknown attribute: $attribute");
        }
        $definition = $this->attributes[$attribute];
        $directions = $this->getAttributeOrders();
        if (isset($directions[$attribute])) {
            if ($this->enableMultiSort) {
                if ($directions[$attribute] === SORT_ASC) {
                    $direction = SORT_DESC;
                } else {
                    $direction = null;
                }
            } else {
                $direction = $directions[$attribute] === SORT_DESC ? SORT_ASC : SORT_DESC;
            }

            unset($directions[$attribute]);
        } else {
            $direction = isset($definition['default']) ? $definition['default'] : SORT_ASC;
        }

View on GitHub (pinned to 66f00d18a2)

When it happens

Trigger: Thrown at framework/data/Sort.php:452 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of yiisoft/yii2@66f00d18a2 (2026-08-17). Data as JSON: /api/errors/fe6d18e6d072512c. Report an issue: GitHub.