CakePHP Themed Plugin

Is it possible to use the plugin theme? I have a mobile theme for mobile devices and I would like to use different view files for plugin apps / views. I tried the app / views / themed / THEME / plugin / ... and / app / plugins / PLUGIN / views / themed / THEME / ... nobody seems to work. Thanks in advance.

+4
source share
2 answers

Cakephp 2.x supports this without having to make any changes to the code:

If you (can) convert to using cakephp 2.x, then yes you can (automatically). The ways to view the "mytheme" theme and the "Permissions" plugin would be:

Array ( [0] => /var/vhosts/Project/htdocs/app/View/Themed/Mytheme/Plugin/Permissions/ [1] => /var/vhosts/Project/htdocs/app/View/Themed/Mytheme/ [2] => /var/vhosts/Project/htdocs/app/View/Plugin/Permissions/ [3] => /var/vhosts/Project/htdocs/app/Plugin/Permissions/View/ [4] => /var/vhosts/Project/htdocs/app/View/ [5] => /var/vhosts/Project/htdocs/lib/Cake/View/ [6] => /var/vhosts/Project/htdocs/lib/Cake/Console/Templates/skel/View/ ) 

So, if you have users /index.ctp in the plugin and you want to override it, you should edit:

 /var/vhosts/Project/htdocs/app/View/Themed/Mytheme/Plugin/Permissions/Users/index.ctp 

for the thematic version of OR:

 /var/vhosts/Project/htdocs/app/View/Plugin/Permissions/Users/index.ctp 

for non-thematic version

+4
source

Copy the contents of your theme to: application / views / theme / THEMENAME / plugins / PLUGINNAME / Create the ThemePluginsView class in the application / libs / view / theme _plugins.php

 // app/libs/view/theme_plugins.php if (!class_exists('ThemeView')) App::import('Core', 'view/theme'); class ThemePluginsView extends ThemeView { function __construct(&$controller, $register = true) { parent::__construct($controller, $register); } function _paths($plugin = null, $cached = true) { $paths = parent::_paths($plugin, $cached); if (!is_string($plugin) || empty($plugin) || empty($this->theme)) return $paths; // add app/plugins/PLUGIN/views/themed/THEME path $dirPath = APP . 'plugins' . DS . $plugin . DS . 'views' . DS . 'themed' . DS . $this->theme . DS; if (is_dir($dirPath)) $paths = array_merge(array($dirPath), $paths); return $paths; } } 

Then call it on your app_controller on beforeFilter () or a regular controller on beforeFilter (), for example:

 function beforeFilter() { if (!class_exists('ThemePluginsView')) App::import('Core', 'view/theme_plugins'); $this->view = 'ThemePlugins'; $this->theme = 'THEME_NAME'; } 

Hope this helps

+5
source

Source: https://habr.com/ru/post/1412474/


All Articles