Welcome Guest, Not a member yet? Register   Sign In
Suggestion : Hook callback
#1

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




Theme © iAndrew 2016 - Forum software by © MyBB