2012-05-03 52 views
2

我有我的工作與這種測試代碼.. 我有一個模塊調用ms並和另外一個叫testtest控制器代碼:笨模板庫和HMVC(MX庫)的靜態方法run()的

<?php 
class Test extends MX_Controller { 

    public function __construct() 
    { 
     parent::__construct(); 
     $this->template->title($this->config->item('site_name','app')); 
    } 

    public function index() 
    { 
     $this->template->build('index'); 
    } 
} 

和內部ms代碼:

<?php 
//ms module 
class Msrofi extends MX_Controller { 

    public function __construct() 
    { 
     parent::__construct(); 
     $this->template->title($this->config->item('site_name','app')); 
    } 

    public function index() 
    { 
     $t = Modules::run('test/test/index'); 
     var_dump($t); 
     $this->template->build('index_message'); 
    } 
} 

的問題是,內部test構建功能是嘗試荷蘭國際集團找到index視圖文件中的ms views文件夾不是test views文件夾.. 我檢查了$this->_module,它給我的ms模塊名稱.. 任何一個知道如何解決這個問題?

回答

1

由於test模塊正在被呼叫在ms之一的上下文中,$this->template->build()正在尋找ms模塊中的視圖文件。您可以加載模型和庫跨模塊用同樣的方法,你必須爲你的視覺路徑也這麼做:

class Test extends MX_Controller { 

    public function index() 
    { 
     // This path works only from the "test" module 
     // $this->template->build('index'); 

     // This path works from any module 
     $this->template->build('test/index'); 
    } 
} 

這是一個有點惱人也許有顯式調用模塊本身模塊路徑,但是跨模塊依賴性首先打敗了模塊化的一些目標。

快速旁白:Modules::run()輸出沒有回來,而是直接呼應,所以你不能把它分配給一個變量或print_r/var_dump它不使用輸出緩衝:

ob_start(); 
Modules::run('test/test/index'); 
$t = ob_get_clean(); 
var_dump($t); 
+0

多數民衆贊成工作,但該放出來的'var_dupm($ t)的結果是''字符串「」(長= 0)',即使在日誌中它加載視圖,因爲你提到..但如果我使用'$ this-> load-> view()'它會把視圖文件的內容。 – zaherg

+0

我以前刪除了我談到的那部分答案,我只是重新編輯了它,但我不確定我完全理解你還有什麼問題。 –

+0

即使我只是直接使用'Modules :: run'輸出測試/索引視圖的數據,它將不會輸出任何內容..並且您的代碼也會輸出'string''(length = 0)'..是的,你明白我的問題..它的構建函數沒有輸出任何'test'模塊,只是當你使用模板庫'Moudles :: run'的輸出可以分配給一個變種它不會將數據直接輸出到頁面 – zaherg

0

你可以試着改變所述module.php run方法

下面的例子是我必須使用fix溶液:

  1. 打開THIRD_PARTY/M X/Modules.php
  2. 近75行找

    $緩衝液= ob_get_clean();

  3. 增加其以下:

    如果($輸出=== NULL & & $緩衝=== ''){$ 輸出= CI :: $ APP->輸出 - > get_output() ; }

在這個時候,它應該能夠正常工作......