终于找到了解决方案:
如果有人遇到这个问题,请将以下内容放入您的beforefilter中。
$this->Security->unlockedActions = array('givestar');
并更新libs到Cake 2.3
问题:
我在处理ajax调用时遇到安全组件黑洞的问题。
var id = 1;
$.ajax({
type: "post",
url: "/messages/givestar/",
data: {"id" : id},
dataType: "json"
});
我只是想发送ID给控制器,以便更新ID=id的消息。
但安全组件在所有我的ajax调用中都将我黑洞化。
有人知道如何在激活安全组件的情况下使其工作吗?
谢谢!
你很棒!
-汤姆
有建议吗???
更新2:经过一些测试,我从黑洞处获得了AUTH错误。
From Book:
‘auth’ Indicates a form validation error, or a controller/action mismatch error.
我已经仔细检查了所有的ACO节点,它们都很好。我怀疑在我的ajax调用中,安全组件产生了表单验证错误。
更新:
AppController.php
public $components = array(
'Acl',
'Auth',
'Session',
'Security',
'Cookie'
);
public function beforeFilter() {
$this->Security->blackHoleCallback = 'blackhole';
}
public function blackhole($type) {
$this->Session->setFlash(__('ERROR: %s',$type), 'flash/error');
}
MessagesController.php
public $components = array('RequestHandler');
public function beforeFilter() {
parent::beforeFilter();
}
public function givestar() {
$this->autoRender = false;
if ($this->request->is('ajax')) {
echo 'Working';
}
return;
}
id
还是在ajax调用中隐藏它? - coolguy