Render () content;
public function render($view,$data=null,$return=false){ if($this->beforeRender($view)) { $output=$this->renderPartial($view,$data,true); if(($layoutFile=$this->getLayoutFile($this->layout))!==false) $output=$this->renderFile($layoutFile,array(‘content‘=>$output),true); $this->afterRender($view,$output); $output=$this->processOutput($output); if($return) return $output; else echo $output; }}
When calling render (), renderpartial () is called first ();
public function renderPartial($view,$data=null,$return=false,$processOutput=false){ if(($viewFile=$this->getViewFile($view))!==false) { $output=$this->renderFile($viewFile,$data,true); if($processOutput) $output=$this->processOutput($output); if($return) return $output; else echo $output; } else throw new CException(Yii::t(‘yii‘,‘{controller} cannot find the requested view "{view}".‘, array(‘{controller}‘=>get_class($this), ‘{view}‘=>$view)));}
Renderpartial () calls getviewfile ()
Start from here
Public Function getviewfile ($ viewname) {// check whether theme is used. If theme exists and a file can be found in the topic directory, if ($ theme = yii: APP () is returned () -> gettheme ())! = NULL & ($ viewfile = $ theme-> getviewfile ($ this, $ viewname ))! = False) return $ viewfile; // when theme is not used // $ moduleviewpath, $ basepath default view path, that is, the view path under the root directory $ moduleviewpath = $ basepath = yii: APP ()-> getviewpath (); // if it is a module, the resolveviewfile () is returned () // '$ this-> getviewpath ()' is the default view path corresponding to the Controller. // if it is in the module, it will point to the module's views directory if ($ module = $ this-> getmodule ())! = NULL) $ moduleviewpath = $ module-> getviewpath (); return $ this-> resolveviewfile ($ viewname, $ this-> getviewpath (), $ basepath, $ moduleviewpath );}
OK, start calling resolveviewfile ()
Public Function resolveviewfile ($ viewname, $ viewpath, $ basepath, $ moduleviewpath = NULL) {// No View File name if (empty ($ viewname) return false; // no view path for the module ??? // If ($ moduleviewpath = NULL) $ moduleviewpath = $ basepath; // No write extension, use the default extension "php" If ($ Renderer = yii: APP ()-> getviewrenderer ())! = NULL) $ extension = $ Renderer-> fileextension; else $ extension = '. PHP '; if ($ viewname [0] ='/') {// if the view name starts with a double backslash (if (strncmp ($ viewname ,'//', 2) = 0) // 'default view path. view File name '$ viewfile = $ basepath. $ viewname; else // 'module view path. view filename '// according to the parameters passed by getviewfile (), the two are the same ??? $ Viewfile = $ moduleviewpath. $ viewname;} // That is to say, the path starting with a double backslash is the base path of views in the root directory. // if the file name contains '. 'elseif (strpos ($ viewname ,'. ') indicates the path alias of yii $ viewfile = yii: getpathofalias ($ viewname); // It does not start with a double backslash and '. ', the file // In the view path corresponding to the else // controller should be the most frequently used case --- directly write the view name $ viewfile = $ viewpath. directory_separator. $ viewname; If (is_file ($ viewfile. $ extension) return yii: APP ()-> findlocalizedfile ($ viewfile. $ extension); elseif ($ ext Ension! = '. PHP '& is_file ($ viewfile. '. PHP ') return yii: APP ()-> findlocalizedfile ($ viewfile. '. PHP '); else return false ;}
Conclusion:
1. The view path in the controller takes priority over themes
2. The second is the Views under the root directory.
3. Then the alias
4. Finally, the views corresponding to the Controller