I used to employ Javascript alert as a way of debugging my PHP code. But, I just realized that it is not always executed. For example, when you register a hook to be run after the signup process, JavaScript logging will not work in the hook.
First, the hook method is defined in the module manifest.php file:
'hooks' => [
[
'event' => 'onUserCreateAfter',
'resource' => 'User_Plugin_Test',
],
],
Then, onUserCreateAfter
must be defined in the User_Plugin_Test class:
class User_Plugin_Test {
//put your code here
public function onUserCreateAfter($event) {
$log = Zend_Registry::get('Zend_Log');
$userId = Engine_Api::_()->user()->getViewer()->getIdentity();
$log->log('User_Plugin_Test->onUserCreateAfter: User id: ' . $userId, Zend_Log::ERR);
echo '<script>alert("User_Plugin_Test->onUserCreateAfter");</script>';
}
}
However, the Zend log works. Why JavaScript does not run in the hook method.