2012-06-20 38 views
0

我使用Code Igniter,HMVC library和Smarty與this library將Smarty 3,Code Igniter 2和HMVC與smarty的繼承一起使用?

默認情況下,Smarty工作正常,但如果我嘗試使用smarty的繼承功能({extends file="master.tpl"}),那麼我們遇到問題。

擴展功能不會在擴展文件的模塊視圖文件夾中查找(在上面的案例中爲master.tpl),而是僅在application/views/文件夾中查找,並在找不到該錯誤時引發錯誤。

我可以將APPPATH."modules/smartytest/views"添加到smarty配置文件中的$config['template_directory']數組中。但是它會爲數組中的每個項目首先檢查該文件引發錯誤。 filemtime(): stat failed for application/views/master.tpl

這還有個問題,如果我有三個模塊,所有的數組和模塊都有一個master.tpl,那麼無論我調用哪個模塊擴展它都會加載找到的第一個模塊。

那麼,有沒有辦法讓smarty的擴展函數與HMVC模塊很好地配合?

回答

0

啊,找到了一個工作方案,

My_Parser.php編輯在線路30塊,所以它讀取:

// Modular Separation/Modular Extensions has been detected 
if (method_exists($this->CI->router, 'fetch_module')) 
{ 
    $this->_module = $this->CI->router->fetch_module(); 
    //add the current module view folder as a template directory 
    if ($this->_module !== '') 
     $this->CI->smarty->addTemplateDir(APPPATH."modules/".$this->_module.'/views'); 
} 

這種方法的一個缺點是,智者會看在你的應用程序/意見模塊視圖文件夾之前的文件夾。如果有人知道解決方案,那就太棒了。

+0

保護功能_find_view($文件){Yeo ol'忠實的意見文件夾 $ view_folder = APPPATH。 '視圖/';我們的HMVC模塊 $ modules_folder = APPPATH。 '模塊/'; //最終路徑 $ final_path = FALSE; //添加以下行!!!!!!!!!!!!!! $ this - > _ module = $ this-> CI-> router-> fetch_module(); //確保我們有一個模塊 如果($ this - > _ module!==''){ –

+0

Y我的評論被截斷 – Hailwood

+0

我有一種相同類型的問題,但沒有使用HMVC與我的CI聰明如果你能解決它的賞金是你的。有一段時間還在。 http://stackoverflow.com/questions/25541382/smarty-templates-with-codeigniter-cant-load-template-when-too-many-directories –

0

的問題是,CI不檢查使用error_reporting()返回0,因爲Smarty的使用@控制操作: 所以在功能「_exception_handler」的頂部添加一行:

if (error_reporting() == 0) return;

在「_exception_handler」函數(第469行)中的「Common.php」文件中,或者在調用index.php文件中的「CodeIgniter.php」之前創建具有相同名稱的自己的函數。

最好!