기본 로그인 스크립트를 작성 했으므로 이제는 인증 구성 요소에 저장된 데이터를 업데이트 한 다음 데이터베이스에 저장해야합니다. 지금까지 내가 가지고있는 것입니다.cakephp 3.x 사용자 데이터 업데이트
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
$this->Auth->user()->last_activity = date("Y-m-d");
$this->Users->save($this->Auth->user());
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Email or password is incorrect, please try again.'));
}
}
몇 가지 변형을 시도했지만 효과가 없습니다. 어떤 아이디어?
이public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
$userData = $this->Users->get($user['id']);
$userData->last_activity = date("Y-m-d");
if($this->Users->save($userData)){
$user['last_activity'] = $userData->last_activity; // to update auth component
}
// echo $this->Auth->user('last_activity');
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Email or password is incorrect, please try again.'));
}
}
cakephp3에서 기록을 갱신하는 또 다른 방법은 다음과 같습니다 : cakephp3에서
'AuthComponent :: user()'의 반환 값이 객체가 아니라 배열이기 때문에이 코드는 오류를 유발합니다. 오류를 수신 할 때마다 CakePHP에 익숙한 사람들에게 문제가 명백 할지라도 전체 스택 추적 (적절하게 읽을 수있는 방식으로 사용할 수있는 로그에서 이상적으로 복사 됨)을 포함하여 질문에 포함하십시오. – ndm