これが私のプロジェクトです:
ユーザーまたは管理者が使用できるWebサイトがあります。index、viewなどのメソッドを作成しました...これらのビューは、ユーザーと管理者がアクセスできる必要があります。admin_index、admin_editなどのメソッドもあります。管理者が表示する必要があります。
今のところ、すべてのユーザーページは公開されており、管理ページはログインによって保護されています。ユーザーページのログインもお願いしたいのですが、公開ページは/ users/loginのみです。
AuthComponentを使用してこれを行うにはどうすればよいですか?
私がそれをタイプするとき:
public function beforeFilter() {
$this->Auth->allow('login');
}
リダイレクトループがあります。
ご協力ありがとうございました
私はまだ問題を抱えています。これが私のコードです。
AppController
class AppController extends Controller {
public $helpers = array('Text', 'Form', 'Html', 'Session', 'Cache');
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array('controller' => 'users', 'action' => 'login', 'admin' => false),
'loginRedirect' => array('controller' => 'index', 'action' => 'index', 'admin' => true),
'logoutRedirect'=> array('controller' => 'users', 'action' => 'login', 'admin' => false),
)
);
public function beforeFilter() {
$this->Auth->allow('login');
}
}
そして私のUsersController
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow(array('login', 'logout'));
}
public function login(){
if(isset($_SESSION['Auth']['User'])){
return $this->redirect($this->Auth->redirect());
}
if($this->request->is('post')){
if($this->Auth->login()){
return $this->redirect($this->Auth->redirect());
} else{
$this->Session->setFlash('Identifiants incorrects', 'notif');
}
}
}
public function logout() {
$this->Session->setFlash('Vous êtes déconnecté', 'notif', array('type' => 'success'));
$this->redirect($this->Auth->logout());
}
}
まだリダイレクトループがあります。理由がわかりません。