The control of Yii topics is managed by Cthememanager and Ctheme, Cthememanager is registered as a core component when the application is initialized, and the default path for the theme is app/themes/.
Theme Configuration
Because the theme component is registered at the time of application initialization, its configuration and aspects, such as having a custom1 theme under app/themes/
By adding ' theme ' + ' Custom1 ' key-value pairs in the main profile, the Cwebapplication::settheme ($value) initialization theme name will be called when the subject is registered.
Get topics
Topic acquisition Gets the path of the view file from the controller rendering view, by viewing the name passed by the action method
[PHP]View Plaincopy
- Ccontroller::getviewfile ()
- Public function Getviewfile ($viewName)
- {
- if ($theme =yii::app ()->gettheme ())!==null && ($viewFile =$theme->getviewfile ($ This,$viewName))!==false)
- return $viewFile;
- $moduleViewPath =$basePath =yii::app ()->getviewpath ();
- if ($module =$this->getmodule ())!==null)
- $moduleViewPath =$module->getviewpath ();
- return $this->resolveviewfile ($viewName,$this->getviewpath (),$basePath,$ Moduleviewpath);
- }
[PHP]View Plaincopy
- Ctheme::etviewfile ()
- /**
- * Finds The view file for the specified controller ' s view.
- * @param Ccontroller $controller the Controller
- * @param string $viewName The view name
- * @return String The view file path. False If the file does not exist.
- */
- Public function Getviewfile ($controller,$viewName)
- {
- $moduleViewPath =$this->getviewpath (); //Get View directory path, default is App/themes/custom1/view
- if ($module =$controller->getmodule ())!==null)
- $moduleViewPath. ='/'. $module->getid (); //If module is present, directory path App/themes/custom1/view/moduleid
- return $controller->resolveviewfile ($viewName,$this->getviewpath ().' /‘. $controller->getuniqueid (),$this->getviewpath (),$moduleViewPath);
- }
Back to Ccontroller get the specific view file path, the view name has three special names
1, starting with//is relative to the application level of the view path
2. Start with/begin with a basic view path relative to module
3. xx.xx is an alias view
[PHP]View Plaincopy
- Public function Resolveviewfile ($viewName,$viewPath,$basePath,$moduleViewPath =null)
- {
- if (empty ($viewName))
- return false;
- if ($moduleViewPath ===null)
- $moduleViewPath =$basePath;
- if ($renderer =yii::app ()->getviewrenderer ())!==null)
- $extension =$renderer->fileextension;
- Else
- $extension ='. php ';
- if ($viewName [0]==='/')
- {
- if (strncmp ($viewName,'//', 2) ===0)
- $viewFile =$basePath. $viewName;
- Else
- $viewFile =$moduleViewPath. $viewName;
- }
- Else if (strpos ($viewName,'. '))
- $viewFile =yii::getpathofalias ($viewName);
- Else
- $viewFile =$viewPath. Directory_separator. $viewName;
- if (is_file ($viewFile. $extension))
- return Yii::app ()->findlocalizedfile ($viewFile. $extension);
- Else if ($extension!=='. php ' && is_file ($viewFile. php '))
- return Yii::app ()->findlocalizedfile ($viewFile. php ');
- Else
- return false;
- }
In the view file, a reference to the style JS and the picture in the theme is required to use the Yii::app ()->theme->baseurl as the BaseURL.
Yii Framework Analysis Note 12: Topic Management