I started an app with CakePHP3 and i need to record some users's actions. So, I have migrated my log structure, I have baked my controller & model and now, I try to get a log when a user log in.
I updated my UsersController like this:
namespace AppController;
use AppControllerAppController;
use AppModelTableLogsTable;
use AppModelEntityUser;
use AppModelEntityLog;
class UsersController extends AppController {
public function login(){
$this->viewBuilder()->layout('external');
$user = $this->Users->newEntity();
if($this->request->is('post')){
$user = $this->Auth->identify();
if($user){
//DOING : enregistrement valide$log = new Log();
$log->user_id = 1;
$log->action = 'lorem ipsum';
$log->target_user = 0;
$log->target_object = 0;
$log->comment = 'test';
$logs = new LogsTable();
$logs->save($log);
$this->Auth->setUser($user);
if($this->Auth->user('security') == 'admin'){
return $this->redirect(['action' => 'admin_index']);
}else{
return $this->redirect($this->Auth->redirectUrl());
}
}
//TODO : enregistrement faux
$this->Flash->error(__('Email or password are wrong.'));
}
$this->set(compact('user'));
$this->set('_serialize', ['user']);
}
}
But it doesn't work, I have the error message for the save() :
Error: Call to a member function transactional() on a non-object
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…