HMVC MX_Controller没有加载CI'_output函数

时间:2013-01-16 08:02:22

标签: codeigniter codeigniter-2 hmvc

通常,扩展CI_Controller可让您使用函数_output来渲染html输出。

我正在使用HMVC。 MX_Controller未加载_output功能。

我测试了它并运行了几次。

问题:

1 - MX_Controller是否继承CI_Controller

2 - 如何实施_output

1 个答案:

答案 0 :(得分: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;

然后将此添加到您的hooks配置中。

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

最后将“custom_output.php”文件添加到hooks目录并添加它。

<?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,但它确实有效。 :)