• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.