Search code examples
controlleryiifile-location

How to use Yii controller located in folder rather than default `protected/controller`?


In Yii, when access to <app-host>/index.php?r=<mycontroller>/<myaction>, the framework will start to run code in protected/controller/<MyController>Controller.php

I want to that code to be located in another folder, says protected/anotherFolder, while other controllers remain as-is. How to do that?

Regards


Solution

  • Thanks to mdomba on yii forum at this post, I found the answer using CWebApplication::controllerMap - in the loading state of the application we call

    Yii::app()->controllerMap['yourControllerName']='path.alias.to.your.controller.file.without.dotPHP';
    

    You can use controllerMap - http://www.yiiframew...ollerMap-detail