Allowing a Specific Page in Cakephp

后端 未结 2 756
没有蜡笔的小新
没有蜡笔的小新 2020-12-20 23:09

I understand how to allow certain controller actions for non-logged in users. But, I can\'t find any documentation on how to allow access to specific pages. The controller

相关标签:
2条回答
  • 2020-12-20 23:55

    I'm afraid you can't do that using the standard functions that AuthComponent gives you. You have to create your own logic for that in the pages_controller's display action.

    Something like (pseudo-code style)

    # in app/controllers/pages_controller.php
    var $allowedPages = array('one', 'two');
    
    function display($page) {
        if(in_array($page, $allowedPages) || $this->User->loggedin) {
            $this->render($page);
        } else {
            $this->render('not_allowed');
        }
    }
    
    0 讨论(0)
  • 2020-12-21 00:09

    In CakePHP 3.x you can accomplish your goal by specifying the full action in the PagesController beforeFilter action:

    public function beforeFilter(Event $event) {
      parent::beforeFilter($event);
    
      $this->Auth->allow(
        ['controller' => 'pages', 'action' => 'display', 'about']
      );
    }
    
    0 讨论(0)
提交回复
热议问题