这是我的项目:
我有一个可供用户或管理员使用的网站。我创建了诸如索引、视图等方法……这些视图必须可供用户和管理员访问。我也有admin_index、admin_edit等方法。它们必须由管理员查看。
目前所有用户页面都是公开的,管理页面受登录保护。我也想要求登录用户页面。唯一的公共页面是/users/login。
如何使用 AuthComponent 做到这一点?
当我输入:
public function beforeFilter() {
$this->Auth->allow('login');
}
我有一个重定向循环。
谢谢您的帮助
我仍然有问题。这是我的代码。
应用控制器
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');
}
}
还有我的用户控制器
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());
}
}
我仍然有重定向循环。我不明白为什么。