1

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

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
  • why do you need to change the location of controllers folder from Yii built in? – aslingga Nov 02 '11 at 08:59
  • As Kor has pointed out, I would like to group the logic into its own folder. A 'logic' involves controller/view/model. A module meets my need. – Nam G VU Nov 02 '11 at 17:29

4 Answers4

6

Open up <app-host>/index.php, edit to

//...
require_once($yii);
$app = Yii::createWebApplication($config);
$app->setControllerPath('protected/anotherFolder');
$app->run();
Elvan
  • 621
  • 3
  • 4
5

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

Nam G VU
  • 33,193
  • 69
  • 233
  • 372
3

You can add to config file

'controllerPath' => 'your_new_controller_path',

The same with view path

'viewPath' => 'path_to_template_folder',
trejder
  • 17,148
  • 27
  • 124
  • 216
user1954544
  • 1,619
  • 5
  • 26
  • 53
3

If I got you, you want to split the web logic into different "folders", or (in a more yii-ly way) modules. For instance, to have all the administrating stuff into another place and get to this using r=admin/users, for instance

If you have your gii manager activated, go to /index.php?r=gii, and create a module. That's it. You can then create controllers inside protected/modules/<module-name>/controllers/ and call them using that path. Of course, views are also stored inside that

Sergi Juanola
  • 6,531
  • 8
  • 56
  • 93