终于找到了解决方案:
如果有人遇到此问题,请将其放入您之前的过滤器中。
$this->Security->unlockedActions = array('givestar');
并将库更新到蛋糕 2.3
问题:
我正在努力解决安全组件在我的 ajax 调用中给我黑洞的问题。
变量 ID = 1;
$.ajax({
type: "post",
url: "/messages/givestar/",
data: {"id" : id},
dataType: "json"
});
我只是尝试发送控制器的 ID 以更新 id=id 的消息
但是安全组件在我的所有 ajax 调用中都让我黑洞。
有人知道我如何在激活安全组件的情况下使其工作?
谢谢!
你真棒!
-汤姆
建议????
UPDATE2经过一些测试,我从黑洞收到 AUTH 错误。
From Book:
‘auth’ Indicates a form validation error, or a controller/action mismatch error.
我已经仔细检查了所有ACO节点,它们很好。我倾向于在我的 ajax 调用中反对来自安全组件的表单验证错误。
更新:
应用控制器.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');
}
消息控制器.php
public $components = array('RequestHandler');
public function beforeFilter() {
parent::beforeFilter();
}
public function givestar() {
$this->autoRender = false;
if ($this->request->is('ajax')) {
echo 'Working';
}
return;
}
在之前的过滤器中:
$this->Security->unlockedActions = array('givestar');
SecurityComponent 第 396 行:
if (!isset($controller->request->data['_Token'])) {
if (!$this->blackHole($controller, 'auth')) {
return null;
}
}
所以我想如果你想保护这个动作,你必须使用额外的生成的"_Token"密钥发送数据。此密钥是使用 Form->secure($fields) 方法生成的(累积方法生成具有正确值的隐藏输入)。