My Own Components Folder in Yii2

You are viewing revision #1 of this wiki article.
This version may not be up to date with the latest version.
You may want to view the differences to the latest version.

next (#2) »

In Yii1 I used to have my own components under the components folder of the structure, now with namespacing this is a little bit different.

I am new with name spaces, so for me was a little difficult to understand it at the beginning.

In this case I was extending DbManager for it to be compatible with the information that I had from Yii1.0 for the Authorization. I needed this to be working in the same database that I had my old application, as I fully upgrade it.

The following is the result of a question asked in the forum in the followin link : Your text to link here...

[list=1] [*]Create the folder

I created my folder under the root directory and it is called components.

[*]Creating the namespace as the folde name.

The class that I created includes the namespace app\components on it.



namespace app\components;

use Yii; use yii\db\Connection; use yii\db\Query; use yii\db\Expression; use yii\base\InvalidCallException; use yii\base\InvalidParamException; use yii\di\Instance; use yii\rbac\DbManager; use yii\rbac\Assignment;


  • Description of MyDbManager *
  • @author ctala */ class MyDbManager extends DbManager {


[*]Calling the Class

Now, in the ocnfiguration file I can call the class without troubles.


    'authManager' => [
        'class' => '\app\components\MyDbManager',

[/code] [/list]

And that's it.

I hope that no one loose as much time as I did trying to do this.