我一直在試圖讓CakePHP ACL與我的新應用程序一起工作,這讓我感到痛苦萬分。由於某些原因ACL似乎沒有工作,但教程是垃圾,並沒有很好地解釋每個組件。例如如何一個ACO鏈接到一個控制器/功能/視圖CakePHP 2.x ACL使其工作的問題
我得到的ACL正常工作,直到獲取頁面,以瞭解用戶是否被允許查看它,也是菜單項,他們可以/不能看到相同的問題。
我注意到,如果我這個代碼添加到我的網頁數組顯示羣組爲空白:
$user = $this->Auth->user();
pr($user);
數組返回:
Array
(
[id] => 80
[first_name] => Bob
[last_name] => Test
[email] => [email protected]
[username] => TestAdmin
[tokenhash] => cleared
[is_active] => 1
[created] => 2014-10-03 16:32:45
[modified] => 2014-10-03 16:32:45
[token_expires_at] =>
[group_id] => 3
[Group] => Array
(
[id] =>
[name] =>
[enabled] =>
[created] =>
[modified] =>
)
)
該網站基本上是一個門戶網站,訪問者應該只能訪問登錄/註冊。和用戶組都可以訪問儀表板,但它最終在一個連續的循環,除非我允許所有人訪問儀表板(由於該組未被識別,我猜)
任何幫助將不勝感激,我意識到你可能需要我發佈代碼,所以請讓我知道你會需要什麼。
在此先感謝
編輯:
我有如下更新了我的AppController,它已開始顯示陣列中的組,因爲它應該!奇怪的感謝推向正確的方向。
AppController.php
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public function beforeRender() {
if((($this->params['controller']==='Users') || ($this->params['controller']==='users'))&&(($this->params['action']=='login') || ($this->params['action']=='register') || ($this->params['action']=='success') || ($this->params['action']=='forgot_password') || ($this->params['action']=='reset_password'))){
$this->theme = 'DataHouseLogin';
}else{
$this->theme = 'DataHouse';
}
parent::beforeRender();
}
public $components = array(
'Acl',
'RequestHandler',
'DebugKit.Toolbar' => array('panels' => array('history' => false)),
'Session',
'Auth' => array(
'authorize' => array(
'Actions' => array(
'actionPath' => 'controllers'
)
),
'loginAction' => array(
'controller' => 'Users',
'action' => 'login'
),
'loginRedirect' => array(
'controller' => 'Dashboard',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'Users',
'action' => 'login'
),
'authError' => 'Did you really think you are allowed to see that?',
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish'
)
)
)
);
public function beforeFilter() {
//$this->Auth->allowedActions = array('display','index','register');
$this->set('user', $this->Auth->user());
$this->set('acl', $this->Acl);
$this->Auth->authorize = array(
'Controller',
'Actions' => array('actionPath' => 'controllers')
);
parent::beforeFilter();
}
public function isAuthorized($user) {
// Default deny
return false;
}
}
你有沒有配置ACL和Auth組件?讓我看看你的AppController-> beforeFilter()函數。 – 2014-10-08 10:33:28
嗨Grzegorz,我已經添加了beforeFilter。 – 2014-10-08 11:17:32