저는 cakePHP 3을 배우면서 인턴쉽을 신청하고 있습니다. 현재는 Official cookbook from cakePHP.org의 자습서를 따르고 있지만이 책은 싫습니다. 매우 혼란 스럽습니다.CakePHP 3 : 사용자는 로그 아웃 할 수 없습니까?
어쨌든 Bookmarker 예제의 단계를 수행했는데 다소 효과가 있습니다.이 책이 로그인 섹션 & 로그 아웃 섹션까지 나에게 말했듯이 모든 작업을 수행했지만 시스템에서 로그 아웃하려고하면 나에게 알려줍니다 "해당 위치에 액세스 할 수있는 권한이 없습니다."
내 프로젝트의 코드가 더 필요하면 알려주십시오.
<?= $this->Html->link(__('Log out'), ['controller' => 'Users', 'action' => 'logout']) ?>
/rootOfProject/src/Controller/AppController.php :
namespace App\Controller;
use Cake\Controller\Controller;
class AppController extends Controller {
public function initialize() {
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'unauthorizedRedirect' => [
'controller' => 'Users',
'action' => 'login'
],
'authorize' => 'Controller'
]);
$this->Auth->allow(['display']);
}
public function isAuthorized($user) {
return false;
}
}
, 내가 server/users/logout
에 대한 하이퍼 링크를 생성하는 다음 코드로 사용자를 유도하고있어 로그 아웃
/rootOfProject/src/Controller/UsersController.php :
namespace App\Controller;
use App\Controller\AppController;
class UsersController extends AppController {
public function index() {
$this->set('users', $this->paginate($this->Users));
}
public function view($id = null) {
$user = $this->Users->get($id, [
'contain' => ['Bookmarks']
]);
$this->set('user', $user);
}
public function add() {
$user = $this->Users->newEntity($this->request->data);
if ($this->request->is('post')) {
if ($this->Users->save($user)) {
$this->Flash->success('The user has been saved.');
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The user could not be saved. Please, try again.');
}
}
$this->set(compact('user'));
}
public function edit($id = null) {
$user = $this->Users->get($id, [
'contain' => []
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success('The user has been saved.');
return $this->redirect(['action' => 'index']);
} else {
$this->Flash->error('The user could not be saved. Please, try again.');
}
}
$this->set(compact('user'));
}
public function delete($id = null) {
$user = $this->Users->get($id);
$this->request->allowMethod(['post', 'delete']);
if ($this->Users->delete($user)) {
$this->Flash->success('The user has been deleted.');
} else {
$this->Flash->error('The user could not be deleted. Please, try again.');
}
return $this->redirect(['action' => 'index']);
}
public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Your username or password is incorrect.');
}
}
public function logout() {
$this->Flash->success('You are now logged out.');
return $this->redirect($this->Auth->logout());
}
public function beforeFilter(\Cake\Event\Event $event) {
$this->Auth->allow(['add']);
}
}
을, 나는의 코드를 변경 한'$ this-> Auth-> $ this-'에'([ '추가']) 허용 > Auth-> allow ([ 'add', 'logout'])''beforeFilter' 메서드를 호출하면 성공했습니다. @ndm –