[英]login in page doesn't redirect with CakePHP ACL
我正在關注CakePHP ACL教程http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-control-application/simple-acl-control-application.html
我有一個名為ImagesController的控制器,該控制器基本上使用戶可以列出所有已上傳的圖像。 也有諸如“上傳”和“刪除”圖像之類的操作。
我也有一個具有登錄和注銷功能的UserController。
我的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 ?>
~
我的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 }
}
因此,現在當我單擊圖像/索引中的操作(例如上載或刪除)時,它會將我發送到用戶/登錄頁面,但是當我嘗試登錄時什么也沒發生,即使我的重定向在第20行中也指向圖像/索引。 是什么賦予了?
與Cake 1.3不同,在Cake 2中,登錄不會自動完成。 這意味着您必須顯式調用$this->Auth->login()
。
看一下本教程中的login()操作。 到目前為止,您從未執行過登錄,這解釋了為什么您沒有被重定向。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.