[英]login in page doesn't redirect with CakePHP ACL
I am following the CakePHP ACL tutorial http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html 我正在关注CakePHP ACL教程http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-control-application/simple-acl-control-application.html
I have a controller called ImagesController that basically lets the user list all the images that have been uploaded. 我有一个名为ImagesController的控制器,该控制器基本上使用户可以列出所有已上传的图像。 There are also actions such as "upload" and "delete" images. 也有诸如“上传”和“删除”图像之类的操作。
I also have a UserController that has login and logout function. 我也有一个具有登录和注销功能的UserController。
My AppController.php looks like this 我的AppController.php看起来像这样
1 <?php
2
3 class AppController extends Controller {
4 public $components = array(
5 'Acl',
6 'Auth' => array(
7 'authorize' => array(
8 'Actions' => array('actionPath' => 'controllers')
9 )
10 ),
11 'Session'
12 );
13 public $helpers = array('Html', 'Form', 'Session');
14
15 public function beforeFilter() {
16 // $this->Auth->actionPath = 'controllers/';
17 //Configure AuthComponent
18 $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
19 $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
20 $this->Auth->loginRedirect = array('controller' => 'images', 'action' => 'index');
21 $this->Auth->allow('display');
22 // $this->Auth->allow('*');
23 }
24 }
25
26
27 ?>
~
My UsersController.php looks like this 我的UsersController.php看起来像这样
<?php
2 App::uses('AppController', 'Controller');
3 /**
4 * Users Controller
5 *
6 * @property User $User
7 */
8 class UsersController extends AppController {
30 public function beforeFilter() {
31 parent::beforeFilter();
32 //$this->Auth->allow("initDB"); // remove this later
33 $this->Auth->allow('login', 'logout');
34 }
35 public function login() {
36 if ($this->Session->read('Auth.User')) {
37 $this->Session->setFlash('You are logged in!');
38 $this->redirect('/', null, false);
39 }
40 }
41 public function logout() {
42 //Leave empty for now.
43 $this->Session->setFlash('Good-Bye');
44 $this->redirect($this->Auth->logout());
45 }
}
So now when I click on an action in images/index such as upload or delete, it sends me to user/login page but when I try to log in nothing happens, even though I have my redirect pointed to images/index in line 20. What gives? 因此,现在当我单击图像/索引中的操作(例如上载或删除)时,它会将我发送到用户/登录页面,但是当我尝试登录时什么也没发生,即使我的重定向在第20行中也指向图像/索引。 是什么赋予了?
Unlike Cake 1.3, in Cake 2, the login is not done automatically. 与Cake 1.3不同,在Cake 2中,登录不会自动完成。 This means you have to call $this->Auth->login()
explicitely. 这意味着您必须显式调用$this->Auth->login()
。
Have a look at the login() action in the tutorial . 看一下本教程中的login()操作。 So far, you never perform the login, and that explains why you are not redirected. 到目前为止,您从未执行过登录,这解释了为什么您没有被重定向。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.