0302 CI2 Hooks

Youngin Lee·2021년 3월 2일
0
post-thumbnail

Hooks - Extending the Framework Core 🔗

Enabling Hooks

application/config/config.php file;

$config['enable_hooks'] = TRUE;

Defining a Hook

appication/config/hooks.php file;


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

Multiple Calls to the Same Hook

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

$hook['pre_controller'][] = array(
                                'class'    => 'MyOtherClass',
                                'function' => 'MyOtherfunction',
                                'filename' => 'Myotherclass.php',
                                'filepath' => 'hooks',
                                 'params'   => array('red', 'yellow')
                                );

Notice the brackets after each array index:

$hook['pre_controller'][]

Hook points

  • post_controller_constructed Called immediately after your controller is instantiated, but prior to any method calls happening.
profile
🤔🤔

0개의 댓글