Reputation: 135
In Yii when you using render in a widget or controller, you only need to give the file name (without .php) as a parameter, like this :
$this->render('forum', array('data'=>$data));
For example when I using this function in Class extends CWidget, Yii will try to find forum.php inside /protected/components/views
How can I change this default path to some other where ? for all my widget class (all class extends CWidget) ? and what if I only want to change the path for some of my widget ?
Upvotes: 0
Views: 2392
Reputation: 1546
You can simply do a $this->render('//path/forum', array('data'=>$data));
, where the //
points to the main view directory, usually protected/views
.
You can also use an aliased path with dot notation:
$this->render('application.myviews.test'); // would render protected/myviews/test.php
$this->render('webroot.test'); // would render htdocs/test.php
Upvotes: 1
Reputation: 5094
You need to override the getViewPath method of the CWidget class
eg:-
class CMyWidget extends CWidget{
// Returns the directory containing the view files for this widget.
public function getViewPath($checkTheme=false){
// this method does the task of finding the view files containing directory.
// so override it
}
// This method will look for the view under the widget's getViewPath viewPath.
public function getViewFile($viewName)
{
// override it
}
}
And finally when creating widgets you will have to extend the CMyWidget class instead of CWidget
Upvotes: 1