CakePHP主题插件视图

Mic*_*ael 4 cakephp cakephp-1.3

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

Sud*_*oti 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;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在beforeFilter()上的app_controller或beforeFilter()上的常用控制器上调用它,如:

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

希望能帮助到你