我正在研究一個應用程序,該應用程序將擁有6個ARO組以覆蓋所需的權限範圍。對每個方法都有* _add,* _edit,* _index,* _view等方法是最好的做法嗎?這似乎有點代碼過載和維護頭痛。在「最便宜」的方式我能想象與路由處理它是一樣的東西:CakePHP w/ACL:許多組的最佳做法是路由?
// core: edit
function _edit($id = null)
{
// do stuff
}
function admin_edit($id = null)
{
$this->_edit($id);
}
function manager_edit($id = null)
{
$this->_edit($id);
}
function clerk_edit($id = null)
{
$this->_edit($id);
}
/* ...and on and on... */
而且在必要時,比如說,一組被允許只能編輯用戶自己的項目,或類似的限制折騰。
還有另一種推薦的技術,或者這是最好的做法嗎?
你可能想檢查這個 - http://stackoverflow.com/questions/54230/cakephp-acl-database-setup-aro-aco-structure – bancer 2010-06-21 22:08:25
我不去'最佳實踐',但如果我做了,那不會是一個。 – Leo 2010-06-22 08:08:08
有時候過濾用戶很有用。我在app_controller的beforeRender方法中設置了一些視圖變量。 $ usersIndexAllowed = $ this-> Acl-> check($ user,「users/index」); $ configureAllowed = $ this-> Acl-> check($ user,「siteAdmins/configure」); $ this-> set(compact('usersIndexAllowed','configureAllowed')); – Leo 2010-06-22 08:16:44