PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, February 16, 2022

[FIXED] How in Yii 2 access AR object as component?

 February 16, 2022     php, web, yii, yii2     No comments   

Issue

Actually, I want have access to some AR object in anywere. So I want access to this ojb as yii component.

Like as Yii using this for user: Yii::$app->user->identity - User component contains User AR object.

I want store my Page AR in component. So, it's look like something: Yii::$app->page->page - Page AR is a propery of Page component. Not very nice :(. This is the only way?


Solution

In config you can set it. Like user is set and adapt it to your requirements.

$config = [
    ...
    'components'=>[
        ....
        'user' => [
            'class'=>'yii\web\User',
            'identityClass' => 'common\models\User',
            ...
        ],
        ...
    ],
...
];

Read more in yii2 documentation on this link



Answered By - tigrasti
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,262,016

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing