I need to set viewPath dynamically based on some conditions in a controller action. I am aware of a method by placing a method called getViewPath() in your controller as below:
public function getViewPath() {
$controllername = $this->getId();
$newPath = "application.views.extra";
$newPath = YiiBase::getPathOfAlias($newPath);
return $newPath;
}
But as i said earlier i need to set viewPath based on a condition. like this:
public function actionView($section) {
switch ($section) {
case 'yoga':
$viewpath = 'yoga';
break;
case 'cycling':
$viewpath = 'cycling';
break;
}
// Now this should render from either:
1. protected/views/yoga/
2. protected/views/cycling/
$this->render('view');
}
Controller class has getViewPath() but not setViewPath() and viewPath property is also readonly.
Appreciate any help with this.
Using
//in a render path defaults toprotected/views/, so you can do the following: