Yii:如何更改渲染功能的默认路径?

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 ?

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

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