SOでかなりの数の同様の問題を見てきましたが、私の質問に答えたり、これを解決するのに役立つものはありませんでした...基本的に、NewsControllerの $this->auth->allow 行をコメントアウトすると(私は認証された人がログイン/登録以外のすべてのアクションにアクセスできるようにする場合)、ログインの無限ループが発生します。すべてのユーザーがニュースコントローラーのインデックスアクションにアクセスできるようにすると、正常に動作します。これがログイン時にループする理由はありますか?
AppController
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array('controller' => 'users', 'action' => 'login'),
'loginRedirect' => array('controller' => 'news', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authorize' => array('Controller')
)
);
ユーザーコントローラー
<?php
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('register');
}
public function login() {
$this->layout = 'eprime_empty';
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
$this->Session->setFlash('Invalid username or password, try again', 'default', array('class' => 'warning'));
}
}
}
public function logout() {
$this->redirect($this->Auth->logout());
}
ニュースコントローラー
<?php
class NewsController extends AppController {
public $helpers = array('Html', 'Form', 'Session');
public function beforeFilter() {
parent::beforeFilter();
// $this->Auth->allow('index', 'view');
}
public function index() {
$this->set('news', $this->News->find('all'));
}