通常,扩展CI_Controller
允许您使用该函数_output
来呈现 html 输出。
我正在使用 HMVC。MX_Controller
不加载_output
功能。
我已经对其进行了测试并运行了几次。
问题:
1 - 是否MX_Controller
继承CI_Controller
?
2 - 我该如何实施_output
?
通常,扩展CI_Controller
允许您使用该函数_output
来呈现 html 输出。
我正在使用 HMVC。MX_Controller
不加载_output
功能。
我已经对其进行了测试并运行了几次。
问题:
1 - 是否MX_Controller
继承CI_Controller
?
2 - 我该如何实施_output
?
似乎 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,但它有效。:)