3

我在我的应用程序中向未经身份验证的用户显示静态页面时遇到问题。

我正在使用 cake 2.1,我的 AppController.php 是这样的:

App::uses('Controller','Controller');

class AppController extends Controller {
    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
            'logoutRedirect' => array('controller' => 'users', 'action' => 'login')
        )
    );

    public function beforeFilter() {
        $this->Auth->allow('display');
    }
}

请帮我。谢谢!

4

3 回答 3

1

您很接近,但该display操作不是AppController. 它属于PagesController相反。

尝试将此逻辑添加到PagesController位于app/Controllers/PagesController.php. 这应该够了吧。

于 2012-09-19T10:34:27.850 回答
1

You need to do this in PagesController

public function beforeFilter() {
        parent::beforeFilter();
        $this->Auth->allow('display');
}

At least it worked for me. Hope it helps someone else.

于 2015-04-04T01:55:49.147 回答
0

应用控制器.php

class AppController extends Controller {

...
  public function beforeFilter() {
    $this->Auth->allow('index', 'view');
    $this->set('loggedUser', $this->Auth->user());

    $this->loadModel('Evento');
    $this->set('eventos', $this->Evento->find('all'));
  }

}

PagesController.php

class PagesController extends AppController {

public function beforeFilter() {
    parent::beforeFilter();
    // Allow users to register and logout.
    $this->Auth->allow('display');
}
 ...
于 2014-05-06T00:22:18.403 回答