CodeIgniter Forums
Suggestion : Hook callback - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Development (https://forum.codeigniter.com/forumdisplay.php?fid=6)
+--- Forum: CodeIgniter 3.x (https://forum.codeigniter.com/forumdisplay.php?fid=17)
+--- Thread: Suggestion : Hook callback (/showthread.php?tid=64617)



Suggestion : Hook callback - djha - 03-12-2016

Hi,

Hook allows to pass parameters only in the configuration array.

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

A great feature could be used the returned values of method as hook parameters.

For example, for the hook "Post Controller", params will be the values returned by the Controller/Method called.
In this case, you can used this values to render view by the hook.

Code:
// Method controller
function index()
{
return array('Title'=>'CI is cool');
}

// Hook method
function postcontroller_hook($data)
{
 $ci = get_instance();
 $path = $ci->router->fetch_class() . '/' . $ci->router->fetch_method() . '.php';
 $ci->load->view($path, $data);
}