Question

Normally, extending CI_Controller lets you use the function _output for rendering html outputs.

I'm using HMVC. MX_Controller doesn't load _output function.

I've tested it and run a couple of times.

Questions:

1 - Does MX_Controller inherits CI_Controller?

2 - How can I implement _output?

Était-ce utile?

La solution

It seems like codeigniter-modular-extensions-hmvc does indeed break the _output() functionality. I can't figure out how to submit the bug on bitbucket: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc

My workaround involved overriding the Output class & adding a hook to fire a custom output method. Here's what I did.

Overwrite the main Output class:

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();
    }
}

Then enable hooks in your config.

$config['enable_hooks'] = TRUE;

Then add this to your hooks config.

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

Finally add the "custom_output.php" file to your hooks directory and add this.

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

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

If you don't need to access any class variables, you can just edit the output right in the custom_output() function and not worry about overriding the Output class.

Very hacky, but it works. :)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top