2016-09-02 43 views
1

我正在關注CakePHP(最新)BookMarkkers教程(第2部分 - 身份驗證)。CakePHP AppController奇怪的行爲

'authorize' => 'Controller', 

,然後阻止我從能夠訪問任何用戶列表或標籤列表:直到我在AppController.php文件中添加下列一切都正常。我只能看到書籤列表。我已經完成了兩次教程。第一次輸入所有的代碼,然後完全重新安裝框架並剪下代碼,在每個貼上進行測試,看起來這條線破壞了應用程序。在充分的控制器方法應該是這樣的:

public function initialize() 
{ 
$this->loadComponent('Flash'); 
$this->loadComponent('Auth', [ 
    'authorize'=> 'Controller', //added this line - it breaks stuff 
    'authenticate' => [ 
     'Form' => [ 
      'fields' => [ 
       'username' => 'email', 
       'password' => 'password' 
      ] 
     ] 
    ], 
    'loginAction' => [ 
     'controller' => 'Users', 
     'action' => 'login' 
    ], 
    'unauthorizedRedirect' => $this->referer() // added this line - not sure if it breaks stuff on its own 
]); 

// Allow the display action so our pages controller 
// continues to work. 
$this->Auth->allow(['display']); 

}

和它是「授權的」和「unauthorizedRedirect」在打破的例子中的initialize()方法的值。有沒有人遇到過這種行爲? 在Firefox中,我收到一個頁面,說該頁面沒有正確重定向。註釋掉這兩行,所有工作都很好...

+1

取代「授權」 =>「用戶」在你的代碼,其中用戶在您的控制器的名字.... –

+1

是,@PruthvirajChudasama是正確的。你需要給你的UserController的名字。 –

回答

0

這只是表示您需要登錄才能訪問應用程序的任何URL。如果你想不登錄訪問某些網址然後將其添加在控制器類似$this->Auth->allow('index');