是否可以为插件的视图设置主题?我有一个用于移动设备的移动主题,并且也想为插件应用程序/视图使用不同的视图文件。我已经尝试过 app/views/themed/THEME/plugin/... 和 /app/plugins/PLUGIN/views/themed/THEME/...none 似乎不起作用。提前致谢。
问问题
1825 次
2 回答
5
将主题的内容复制到: app/views/themed/THEMENAME/plugins/PLUGINNAME/在app/libs/view/theme_plugins.php上 创建一个ThemePluginsView类
// 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;
}
}
然后在 beforeFilter() 上的 app_controller 或 beforeFilter() 上的常用控制器上调用它,例如:
function beforeFilter() {
if (!class_exists('ThemePluginsView'))
App::import('Core', 'view/theme_plugins');
$this->view = 'ThemePlugins';
$this->theme = 'THEME_NAME';
}
希望能帮助到你
于 2012-05-15T05:05:02.423 回答
4
Cakephp 2.x 支持这一点,无需进行任何代码更改:
如果您(可以)转换为使用 cakephp 2.x,那么可以(自动)。主题“mytheme”和插件“权限”的视图路径为:
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/
)
因此,如果您在插件中有 Users/index.ctp 并想要覆盖它,您将编辑:
/var/vhosts/Project/htdocs/app/View/Themed/Mytheme/Plugin/Permissions/Users/index.ctp
对于主题版本或:
/var/vhosts/Project/htdocs/app/View/Plugin/Permissions/Users/index.ctp
对于非主题版本
于 2013-06-22T09:27:03.280 回答