How to use hooks in the CI framework

Source: Internet
Author: User
: This article describes how to use hooks in the CI framework and its functions. For more information about PHP tutorials, see. // Hooks source code
// Hooks is the hook. it is mainly used to expand base_system under the CI framework. its main function is,
// Run some developer-defined methods to implement some specific functions
// Define the method to be started at CI startup in application/config/hooks. php
$ Hook ['pre _ controller'] [] = array (
'Class' => 'myclass ',
'Function' => 'myfunction ',
'Filename' => 'myclass. php ',
'Filepath' => 'Hooks ',
'Params' => array ('beer', 'wine', 'snacks ')
);


$ Hook ['pre _ controller'] [] = array (
'Class' => 'myotherclass ',
'Function' => 'myotherfunction ',
'Filename' => 'myotherclass. php ',
'Filepath' => 'Hooks ',
'Params' => array ('red', 'yellow', 'blue ')
);


// The hooks source code first checks whether the hooks (custom similar to the preceding array) exists or whether it is a two-digit array.
If (isset ($ this-> hooks [$ which] [0]) AND is_array ($ this-> hooks [$ which] [0]) {
// If yes, the system executes the loop and runs run_hook.
Foreach ($ this-> hooks [$ which] as $ val ){
$ This-> _ run_hook ($ val );
}
} Else {
// If not, directly run hooks
$ This-> _ run_hook ($ this-> hooks [$ which]);
}


// Set $ this-> in_progress = TRUE below. it mainly prevents calling a hook at the same time. when a new object is added,
// Mark in_progress as false
$ This-> in_progress = TRUE;


If ($ class! = FALSE ){
If (! Class_exists ($ class )){
Require ($ filepath );
}
$ HOOK = new $ class;
$ HOOK-> $ function ($ params );
} Else {
If (! Function_exists ($ function )){
Require ($ filepath );
}


$ Function ($ params );
}
$ This-> in_progress = FALSE;

The above describes how to use hooks in the CI framework and its functions, including some content, and hope to help those who are interested in PHP tutorials.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.