Hook

Navigation:  Components >

Hook

Previous pageReturn to chapter overviewNext page

Hook is a method that help to register resource in appRain core. After registering a hook the target resource become a part of it until we deactivate the component.

 

Register Call Back

In first step we register a hook name with a call back function. See below format to register a hook
 
App::Module('Hook')

   ->setHookName(Hook Name)

   ->setAction(Action Name)

   ->Register(Class Name,Call Back Function);
 
A hook function must call in init() event of a component.
 

Name

Type

Description

Hook Name

Mandatory

Name of the Hook Type.
We have diffident type of the Hook that use to register Controller, Model, UI, Menu, InformationSet etc.

Action Name

Mandatory

Action Name of desired hook

Class Name

Mandatory

Class Name of the Call Back Hook.
Generally we used same registration class name

Class Back Function

Mandatory

Function Name of the call back.

 
See below example to register a model:
 
class Component_Appstore_Register extends appRain_Base_Component
{
   public function init()
   {
       App::Module('Hook')
           ->setHookName('Model')
           ->setAction("register_model")
           ## get_class($this) return 'Component_Appstore_Register' means same class
           ->Register(get_class($this),"register_model");
   }
}
 
Execute Call back to register resource:

In this step we work in registered call back function to add resource.  Each Hook has separate method to load resource. See below example to load an model: 
 
class Component_Appstore_Register extends appRain_Base_Component
{
    public function register_model()
    {
        $srcpaths = Array();
        $srcpaths[] =   array(
            'name'=>'Item',
            'model_path'=>$this->attachMyPath('models')
        );
 
        $srcpaths[] = array(
            'name'=>'Order',
            'model_path'=>$this->attachMyPath('models')
        );
 
        return $srcpaths;
    }
}

 

See also: ACL,Addon, CategorySet, Controller, Helper, InformationSet, Model, Sitemenu, Sitesettings, UI, URIManager, Admin Notice