yiisoft/yii2 · error · InvalidConfigException

The user application component must be available to specify

Error message

The user application component must be available to specify roles in AccessRule.

What it means

Error "The user application component must be available to specify roles in AccessRule." thrown in yiisoft/yii2.

Source

Thrown at framework/filters/AccessRule.php:235

    /**
     * @param User $user the user object
     * @return bool whether the rule applies to the role
     * @throws InvalidConfigException if User component is detached
     */
    protected function matchRole($user)
    {
        $items = empty($this->roles) ? [] : $this->roles;

        if (!empty($this->permissions)) {
            $items = array_merge($items, $this->permissions);
        }

        if (empty($items)) {
            return true;
        }

        if ($user === false) {
            throw new InvalidConfigException('The user application component must be available to specify roles in AccessRule.');
        }

        foreach ($items as $item) {
            if ($item === '?') {
                if ($user->getIsGuest()) {
                    return true;
                }
            } elseif ($item === '@') {
                if (!$user->getIsGuest()) {
                    return true;
                }
            } else {
                if (!isset($roleParams)) {
                    $roleParams = !is_array($this->roleParams) && is_callable($this->roleParams) ? call_user_func($this->roleParams, $this) : $this->roleParams;
                }
                if ($user->can($item, $roleParams)) {
                    return true;
                }

View on GitHub (pinned to 66f00d18a2)

When it happens

Trigger: Thrown at framework/filters/AccessRule.php:235 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/33775ab8bf72cbc0. Report an issue: GitHub.