CakePHP主题插件视图

时间:2012-05-15 04:52:48

标签: cakephp cakephp-1.3

是否可以主题插件的视图?我有一个移动设备的移动主题,并希望使用不同的视图文件的插件应用程序/视图。我试过app / views / themed / THEME / plugin / ...和/app/plugins/PLUGIN/views/themed/THEME/...none似乎工作。提前谢谢。

2 个答案:

答案 0 :(得分:5)

将主题内容复制到: 应用/视图/主题/ THEMENAME /插件/ 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';
}

希望有所帮助

答案 1 :(得分: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

主题版本OR:

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

为非主题版本