在我的应用程序中,我正在使用安全组件,并在app控制器中定义,如此
public $components = array('Security');
我已经创建了这样的表单
<?php
echo $this->Form->create('Admin', array('id' => 'form',"url"=>array("plugin"=>"admins","controller"=>"admins","action"=>"save","admin"=>true)));
echo $this->Form->hidden("submit_type",array("id" => "id_submit_type","value" => ""));
echo $this->Form->input("username");
echo $this->Form->input("password");
echo $this->Form->button(__('Save'),array("id" => "save","class" => "form-button"));
echo $this->Form->button(__('Save & Cont'),array("id" => "savec","class" => "form-button"));
echo $this->Form->end();
?>
在Javascript中我正在更新隐藏的字段值
<script type="text/javascript">
$(document).ready(function()
{
$('#save, #savec').click(function() {
if($(this).is('#save'))
$('#id_submit_type').val("S");
else
$('#id_submit_type').val("C");
$('#form').submit();
});
});
</script>
点击保存按钮后
CORE/Cake/Controller/Component/SecurityComponent.php line 234 → SecurityComponent->blackHole(AdminsController, string)
[internal function] → SecurityComponent->startup(AdminsController)
CORE/Cake/Utility/ObjectCollection.php line 131 → call_user_func_array(array, array)
[internal function] → ObjectCollection->trigger(CakeEvent)
CORE/Cake/Event/CakeEventManager.php line 247 → call_user_func(array, CakeEvent)
CORE/Cake/Controller/Controller.php line 670 → CakeEventManager->dispatch(CakeEvent)
CORE/Cake/Routing/Dispatcher.php line 183 → Controller->startupProcess()
CORE/Cake/Routing/Dispatcher.php line 161 → Dispatcher->_invoke(AdminsController, CakeRequest, CakeResponse)
APP/webroot/index.php line 97 → Dispatcher->dispatch(CakeRequest, CakeResponse)
如果我正在评论更新javascript中的隐藏字段
我的功能正常并将数据保存到表中
请告诉我如何在使用安全组件
时在javascript中设置隐藏变量值答案 0 :(得分:1)
尝试这样,我不知道它是否是正确的解决方案。但它对我来说是正常的。 在beforeFilter函数中编写以下代码
$this->Security->disabledFields = array('hiddenfield1', 'hiddenfield2'); // set the hidden fields like this
function beforeFilter() {
$this->Security->disabledFields = array('submit_type'); // for your code
}