Description of hooks usage and its role in CI framework

Source: Internet
Author: User
Tags php tutorial
Hooks source
Hooks is the hook, the main role is the CI framework under the expansion of Base_system, his main role is when the CI started,
Run some developer-defined methods to implement some specific functions
The method definition that is defined in application/config/hooks.php to start at CI startup
$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 ')
);


Hooks source first determine whether the hooks (that is, a custom similar to the above array) exists or is not a two-bit array
if (Isset ($this->hooks[$which][0]) and Is_array ($this->hooks[$which][0]) {
If yes, loop and run Run_hook
foreach ($this->hooks[$which] as $val) {
$this->_run_hook ($val);
}
}else{
If not, run the hooks directly
$this->_run_hook ($this->hooks[$which]);
}


The following setting $this->in_progress = TRUE; Prevents the invocation of a hook at the same time, when new objects are
We're going to 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 the CI framework hooks use and its role, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.