Search code examples
phpcodeignitercodeigniter-3

In Codeigniter how to make library wait until view is rendered


I want to show a modal when triggered by my custom class library, but without explicity calling any of its methods from outside.

I would have to wait until view template is loaded.

How can I make my library's methods wait until view is loaded?

As first step I have already added my library to the autoload array.


Solution

  • Did you try Hooks? Following may work but not sure. Didn't try myself.

    $hook['post_controller'] = array(
            'class'    => 'MyClass',
            'function' => 'Myfunction',
            'filename' => 'Myclass.php',
            'filepath' => 'hooks',
            'params'   => array('beer', 'wine', 'snacks')
    );
    

    Reference - https://codeigniter.com/userguide3/general/hooks.html