Yii Framework Analysis Note 12: Topic Management

Source: Internet
Author: User
Tags vars

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
  1. Ccontroller::getviewfile ()
  2. Public function Getviewfile ($viewName)
  3. {
  4. if ($theme =yii::app ()->gettheme ())!==null && ($viewFile =$theme->getviewfile ($ This,$viewName))!==false)
  5. return $viewFile;
  6. $moduleViewPath =$basePath =yii::app ()->getviewpath ();
  7. if ($module =$this->getmodule ())!==null)
  8. $moduleViewPath =$module->getviewpath ();
  9. return $this->resolveviewfile ($viewName,$this->getviewpath (),$basePath,$  Moduleviewpath);
  10. }
[PHP]View Plaincopy
  1. Ctheme::etviewfile ()
  2. /**
  3. * Finds The view file for the specified controller ' s view.
  4. * @param Ccontroller $controller the Controller
  5. * @param string $viewName The view name
  6. * @return String The view file path. False If the file does not exist.
  7. */
  8. Public function Getviewfile ($controller,$viewName)
  9. {
  10. $moduleViewPath =$this->getviewpath (); //Get View directory path, default is App/themes/custom1/view
  11. if ($module =$controller->getmodule ())!==null)
  12. $moduleViewPath. ='/'.  $module->getid (); //If module is present, directory path App/themes/custom1/view/moduleid
  13. return $controller->resolveviewfile ($viewName,$this->getviewpath ().' /‘.  $controller->getuniqueid (),$this->getviewpath (),$moduleViewPath);
  14. }

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
  1. Public function Resolveviewfile ($viewName,$viewPath,$basePath,$moduleViewPath =null)
  2. {
  3. if (empty ($viewName))
  4. return false;
  5. if ($moduleViewPath ===null)
  6. $moduleViewPath =$basePath;
  7. if ($renderer =yii::app ()->getviewrenderer ())!==null)
  8. $extension =$renderer->fileextension;
  9. Else
  10. $extension ='. php ';
  11. if ($viewName [0]==='/')
  12. {
  13. if (strncmp ($viewName,'//', 2) ===0)
  14. $viewFile =$basePath.   $viewName;
  15. Else
  16. $viewFile =$moduleViewPath.   $viewName;
  17. }
  18. Else if (strpos ($viewName,'. '))
  19. $viewFile =yii::getpathofalias ($viewName);
  20. Else
  21. $viewFile =$viewPath. Directory_separator.   $viewName;
  22. if (is_file ($viewFile. $extension))
  23. return Yii::app ()->findlocalizedfile ($viewFile.   $extension);
  24. Else if ($extension!=='. php ' && is_file ($viewFile. php '))
  25. return Yii::app ()->findlocalizedfile ($viewFile.  php ');
  26. Else
  27. return false;
  28. }

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.