【发布时间】:2014-10-28 19:27:33
【问题描述】:
我对 cakePhp 2.5.x 中的 Acl 有疑问。我已经完成了 cakephp 食谱告诉我的所有事情,但我仍然有问题。
所以我将我的应用程序设置为有 3 个组。管理员、经理和用户,就像在食谱中一样。 目前我的应用只有 1 个用户,这个用户属于管理员。管理员可以做任何事情。
这是我的 AppController 代码:
class AppController extends Controller {
public $components = array(
'Acl',
'Session',
'Auth' => array(
'loginRedirect' => array(
'controller' => 'users',
'action' => 'index'
),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login'
),
'authenticate' => array(
'Form' => array(
'passwordHasher' => 'Blowfish'
)
),
'authorize' => array(
'Actions' => array('actionPath'=>'controllers'),
),
)
);
public function beforeFilter(){
//not thinked yet
parent::beforeFilter();
//$this->initDB();
}
public function initDB(){
$group = $this->User->MemberOf;
// Allow admins to everything
$group->id = 1;
$this->Acl->allow($group, 'controllers');
}
}
和用户控制器
类 UsersController 扩展 AppController{
public $helpers = array('Html','Form');
public $uses = array("User","Group");
// callbacks
public function beforeFilter(){
parent::beforeFilter();
问题是当我(管理员,我已经登录)想要调用 UsersController cakephp 的“添加”操作时给我这个错误:
Database Error
错误:SQLSTATE[42S22]:找不到列:1054 'where 子句'中的未知列'Aro0.foreignKey'
SQL 查询:SELECT Aro.id,Aro.parent_id,Aro.model,Aro.foreign_key,Aro54Aro54F .aros AS Aro INNER JOIN dotcore.aros AS Aro0 ON (Aro.lft Aro0.lft@98765434@@=@98765434@@=. 987654347@.rght) 其中Aro0.model = '组' AND Aro0.foreignKey = '1' ORDER BY Aro.lft DESC
注意:如果要自定义此错误信息,请创建 app\View\Errors\pdo_error.ctp
我知道在aros表中没有foreignKey字段,但是foreign_key,但是为什么cakephp在where子句中使用foreignKey呢?
请帮我解决这个问题,我找不到任何关于这个问题的帖子/问题,所以我在这里问这个问题。 我非常感谢您的回复。谢谢
【问题讨论】:
-
aros 模型发生了什么?
-
我们同时遇到同样的问题。看看这个答案,对用户stackoverflow.com/a/17382831/1127933做同样的事情
-
aros @Widrogo 的模型没有任何变化,