在我的bootstrap文件中,我启动了记录器,一切正常。我现在需要的是记录器还记录从zend_auth实例给出的user_id。这是我发起的记录器:
public function _initLogger(){
$resource = $this->getPluginResource('db');
$dbAdapter = $resource->getDbAdapter();
$columnMapping = array(
'level' => 'priorityName',
'priority' => 'priority',
'message' => 'message',
'created' => 'timestamp',
'user_agent'=> 'user_agent',
'get_vars' => 'get_vars',
'post_vars' => 'post_vars',
'ip' => 'ip',
'id_user' => 'id_user',
);
$auth = Zend_Auth::getInstance();
$writerDb = new Zend_Log_Writer_Db($dbAdapter, 'tbl_log', $columnMapping);
$logger = new Zend_Log($writerDb);
$logger->setEventItem('datetime',date('Y-m-d H:i:s'));
$logger->setEventItem('user_agent',$_SERVER['HTTP_USER_AGENT']);
$logger->setEventItem('get_vars',print_r($_GET,true));
$logger->setEventItem('post_vars',print_r($_POST,true));
$logger->setEventItem('ip',$_SERVER['REMOTE_ADDR']);
$logger->setEventItem('id_user',$auth->getIdentity()->id);
$logger->addPriority('login', 10);
$logger->addPriority('logout', 11);
$logger->addPriority('trans', 12);
$logger->addPriority('transfailed', 13);
Zend_Registry::set('logger', $logger);
}
我没有收到任何错误,但未存储或检索用户ID ...
答案 0 :(得分:1)
在引导期间,身份验证信息不可用。您需要添加以下行:
$logger = Zend_Registry::get('logger');
$logger->setEventItem('id_user',$auth->getIdentity()->id);
之后,您将从用户(在登录控制器中)获取身份信息。