2013-01-16 22 views
1

正常情況下,通過擴展CI_Controller,可以使用函數_output來呈現html輸出。HMVC MX_Controller not loading CI'_output function

我正在使用HMVC。 MX_Controller不加載_output功能。

我測試過它並運行了幾次。

問題:

1 - 是否MX_Controller繼承CI_Controller

2 - 如何實施_output

+0

是'MX_Controller'繼承'CI_Controller'。你在說什麼'_output'!我沒有看到它記錄在任何地方! – Broncha

+0

@Broncha - 在**處理輸出部分**看看[here](http://ellislab.com/codeigniter/user-guide/general/controllers.html)** –

+1

@zeekerg,你需要顯示你的代碼。並且使用'_output'有很多後果。沒有代碼預覽 –

回答

1

好像codeigniter-modular-extensions-hmvc確實會破壞_output()功能。我無法弄清楚如何提交bitbucket的錯誤:https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

我的解決方法是覆蓋Output類&添加一個鉤子來觸發自定義輸出方法。這就是我所做的。

覆蓋主要Output類:

class MY_Output extends CI_Output 
{ 
    function __construct() 
    { 
     parent::__construct(); 
    } 

    // Overwrite the output 
    public function my_output() 
    { 
     $content = $this->get_output(); 

     // do stuff to $content here 

     $this->set_output($content); 
     $this->_display(); 
    } 
} 

然後啓用你的配置掛鉤。

$config['enable_hooks'] = TRUE; 

然後將此添加到您的掛鉤配置。

$hook['display_override'][] = array(
    'class' => '', 
    'function' => 'custom_output', 
    'filename' => 'custom_output.php', 
    'filepath' => 'hooks' 
    ); 

最後將「custom_output.php」文件添加到您的掛鉤目錄並添加它。

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

/* 
* Customize the output 
*/ 
function custom_output() 
{ 
    $CI =& get_instance(); 
    $CI->output->my_output(); 
} 

如果您不需要訪問任何類變量,你可以編輯輸出就在custom_output()功能,而無需擔心重寫Output類。

很hacky,但它的作品。 :)