It looks like you're new here. If you want to get involved, click one of these buttons!
class Whatsons_model extends Base_module_model {
<removed irrelevant detail...>
public function after_create_whatsons($data)
{
log_message('debug', __FILE__."::after_create_whatsons: date=".print_r($data, 1));
}
public function before_create_whatsons($data)
{
log_message('debug', __FILE__."::before_create_whatsons: date=".print_r($data, 1));
}
}
$hook['before_create_whatsons'] = array(
'class' => 'Whatsons_model',
'function' => 'before_create_whatsons',
'filename' => 'Whatsons_model.php',
'filepath' => 'models',
'params' => array(),
'module' => 'whatsons',
);
$hook['after_create_whatsons'] = array(
'class' => 'Whatsons_model',
'function' => 'after_create_whatsons',
'filename' => 'Whatsons_model.php',
'filepath' => 'models',
'params' => array(),
'module' => 'whatsons',
);
Comments
Just to confirm, you have an advanced module called "whatsons" at fuel/modules/whatsons. In that advanced module you have a model named Whatsons_model at fuel/modules/whatsons/models/Whatsons_model.php correct? And you are trying to run the hook right before and after model data is saved in the CMS correct?
At first I didn't include a whatson record model, but now that I have, I figured out that it has event handlers available that do what I what them to do, however I never was able to get the before_create and after_create hooks to work - they simply aren't getting invoked.
$hook['before_create_whatsons'] = array( 'class' => 'Whatsons_model', 'function' => 'before_create_whatsons', 'filename' => 'Whatsons_model.php', 'filepath' => 'models', 'params' => array() );
If not, does the model get loaded at all can you tell?
In MY_Hooks.php function _run_hook() uses the following as the $filepath :
fuel/application/../modules/whatsons/models/Whatsons_model.php
while this file actually lives here:
fuel/application/models/whatsons/models/Whatsons_model.php
While investigating this I also noticed another bug in MY_Hooks.php:
the code block starting at line 72:
{ // ----------------------------------- // Add params to data to be passed to hooks // ----------------------------------- if (!empty($params)) { if (!isset($this->hooks[$which])) { $this->hooks[$which]['params'] = array_merge($this->hooks[$which], $params); } else { $this->hooks[$which]['params'] = $params; } } $this->_run_hook($this->hooks[$which]); }
should read like this:
{ // ----------------------------------- // Add params to data to be passed to hooks // ----------------------------------- if (!empty($params)) { if (isset($this->hooks[$which])) { $this->hooks[$which]['params'] = array_merge($this->hooks[$which], $params); } else { $this->hooks[$which]['params'] = $params; } } $this->_run_hook($this->hooks[$which]); }
The actual error is on line 78 - the ! should not be there...