This Hook used to register Model.
Step1: Register Call call back. See below format:
App::Module('Hook')
->setHookName("Model")
->setAction("register_model")
->Register(Call Back Class Name, Call Back Function Name);
Name |
Type |
Description |
---|---|---|
Call Back Class Name |
Mandatory |
Class Name of call back function |
Call Back Function Name |
Mandatory |
Call back function |
Step 2: Register resource in Call back function:
In call back function we return an array with Model information like below
$srcpaths[] = array(
'name'=>Name of Model,
"'path"=>Path
);
Name |
Type |
Description |
---|---|---|
Name of model |
Mandatory |
Name of the model |
Path |
Mandatory |
File path |
Work with installer:
If we crate model Installer then installer folder should be in same path. For example:
Controller path |
/component/testcomponent/model/testmodel.php |
---|---|
template path |
/component/testcomponent/controller/installer/ |
See below example:
class Component_Appstore_Register extends appRain_Base_Component
{
public function init(){
App::Module('Hook')
->setHookName('Model')
->setAction("register_model")
->Register(get_class($this),"register_model");
}
public function register_model()
{
$srcpaths = Array();
$srcpaths[] = array(
'name'=>'Item',
'model_path'=>$this->attachMyPath('models')
);
$srcpaths[] = array(
'name'=>'Order',
'model_path'=>$this->attachMyPath('models')
);
$srcpaths[] = array(
'name'=>'storeComment',
'model_path'=>$this->attachMyPath('models')
);
return $srcpaths;
}
}