我正在尝试记录每个写入操作,因此我在 AppModel 中使用 afterSave 和 afterDelete 回调。基本上我需要登录(暂时):模型,控制器功能,登录用户数据和远程ip似乎我能够获得所有这些,但我不知道如何获得控制器功能名称. 这是我现在拥有的 aftersave 功能:
public function afterSave($created) {
App::uses('Folder', 'Utility');
$month = date("y-m");
if(!is_dir('../tmp/logs/'.$month)) {
$dir = new Folder('../tmp/logs/'.$month, true);
}
App::uses('CakeSession', 'Model/Datasource');
$user_id = CakeSession::read('Auth.User.username');
if($created) {
$id = 'New';
} else {
$id = $this->data[$this->alias]['id'];
}
$str = 'WRITE Action. Model: '.$this->alias.'. Controller: functon_name. ID:'.$id.'. Username: '.$user_id.'. Client IP: '.$this->getIP();
CakeLog::write($month.'/'.date("d-m-y"), $str);
}
谢谢