sacpv04
(Sacpv04)
February 19, 2014, 9:17am
1
Dear all,
in view of yii,we create folder of view by controller name.However, I want to create 2 sites of view: admin and user, is there any ways can do like this:
controller name:ServicesController
for the view, we usually create
views/services/index.php
,but can I create view like this:
views/users/services/index.php
thanks
JFReyes
(Jose Reyes)
February 19, 2014, 9:51am
2
Check the URL Management section in the Guide..
joblo
(Joe)
February 19, 2014, 10:02am
3
You can use modules or override the getViewPath() method of your basecontroller (=Controller.php)
class Controller extends CController {
public $viewSubDir;
public function getViewPath()
{
if(empty($this->viewSubDir)
return parent::getViewPath()
else
{
if(($module=$this->getModule())===null)
$module=Yii::app();
return $module->getViewPath().DIRECTORY_SEPARATOR.$this->viewSubDir.DIRECTORY_SEPARATOR.$this->getId();
}
}
...
}
In your ServiceController
class ServiceController extends Controller
{
public $viewSubDir = 'users';
...
}
Or you can set the viewSubdir in the actions ‘on the fly’ before calling render.
public function actionXY()
{
...
$this->viewSubDir = 'admin';
$this->render(...)
}
Use url manager and module generator