【问题标题】:HMVC MX_Controller not loading CI' _output functionHMVC MX_Controller 未加载 CI' _output 函数
【发布时间】:2023-03-25 05:34:01
【问题描述】:

通常,扩展 CI_Controller 允许您使用函数 _output 来呈现 html 输出。

我正在使用 HMVC。 MX_Controller 不加载 _output 函数。

我已经对其进行了测试并运行了几次。

问题:

1 - MX_Controller 是否继承 CI_Controller

2 - 如何实现_output

【问题讨论】:

  • 是的 MX_Controller 继承 CI_Controller。你在说哪个_output!我没有看到它记录在任何地方!
  • @Broncha - 看看here 处理输出部分
  • @zeekerg,你需要展示你的代码。使用 _output 有很多后果。没有代码预览,没什么好说的
  • 我使用 _output 在页面上设置布局和设置,因此在加载视图之前首先调用 _output 函数。

标签: codeigniter codeigniter-2 hmvc


【解决方案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,但它有效。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-18
    相关资源
    最近更新 更多