我正在关注 CakePHP ACL 教程 http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-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 行中的图像/索引。 是什么赋予了?