我曾经使用Javascript警报作为调试PHP代码的一种方式。但是,我只是意识到它并不总是执行的。例如,当您注册要在注册过程后运行的挂钩时,JavaScript日志记录将在该挂钩中不起作用。
首先,在模块manifest.php文件中定义了hook方法:
'hooks' => [
[
'event' => 'onUserCreateAfter',
'resource' => 'User_Plugin_Test',
],
],
然后,onUserCreateAfter
必须在User_Plugin_Test类中定义:
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>';
}
}
但是,Zend日志有效。为什么JavaScript无法在hook方法中运行。