2012-05-15 88 views
4

主題插件視圖有可能嗎?我有移動設備的移動主題,並希望爲插件應用/視圖使用不同的視圖文件。我已經嘗試應用程序/視圖/主題/ THEME /插件/ ...和/app/plugins/PLUGIN/views/themed/THEME/...無人似乎工作。提前致謝。CakePHP主題插件視圖

回答

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/ 
) 

所以,如果你在插件有用戶/ 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 

對非主題版本

5

你的主題將內容複製到: 應用程序/視圖/主題/ THEMENAME /插件/ PLUGINNAME/應用程序創建一個ThemePluginsView類/庫/視圖/ 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; 
    } 
} 

然後把它在你的app_controller上beforeFilter()或beforeFilter平常控制器(),如:

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

希望它可以幫助