Welcome Guest, Not a member yet? Register   Sign In
How do I pass a parameter to a hook in CodeIgniter?
#1

In CodeIgniter, how can I pass parameters from the context where the hook is called?

Example:

File_Where_Hook_is_Called.php:

PHP Code:
    $this->hooks load_class('Hooks''core');

    $filename 'example.zip';

    $this->hooks->call_hook('site_export_before_delete'); 


config/hooks.php:


PHP Code:
    $hook['site_export_before_delete'][] = array(
            'class'    => 'Foo',
            'function' => 'export_site',
            'filename' => 'Foo.php',
            'filepath' => 'modules/foo/controllers',
            'params'   => [''# Should be $filename from File_Where_Hook_is_Called.php
    ); 


application/modules/foo/controllers/Foo.php:


PHP Code:
    public function export_site($filename) {
        echo $filename); # Should print $filename from File_Where_Hook_is_Called.php
    
Reply




Theme © iAndrew 2016 - Forum software by © MyBB