Aliases

In my controller i have the actions method




public function actions() {

    return array(

        'Action1' => 'application.controllers.actions.Action1',

        'Action2' => 'application.controllers.actions.Action2'

    );

}



That works but I wanted to try and cut out the need for ‘application.controllers’ so created an alias.

//Beginning of config file.

Yii::setPathOfAlias(‘actions’, ‘application.controllers.actions’);




public function actions() {

    return array(

        'Action1' => 'actions.Action1',

        'Action2' => 'actions.Action2'

    );

}



But it now errors out, can I not use aliases in this way?

setPathOfAlias() requires a real path as a second argument, not an alias. If you want to do that in your main config file, then it should look like:




Yii::setPathOfAlias('actions', dirname(__FILE__).'/../controllers/actions'); // it is better to use DIRECTORY_SEPARATOR instead of "/"



ah, my bad, thought you could alias an alias to shorten it.

Yii::setPathOfAlias(‘actions’, Yii::getPathOfAlias(‘application.controllers.actions’));

This won’t work in a config file.

Yea i know, since when config is loaded, the alias for application… is not yet set. That should be used elsewhere