1

在我的应用程序中,我正在使用安全组件并像这样在应用程序控制器中定义

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 中设置隐藏变量值

4

1 回答 1

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
}
于 2013-09-23T08:39:04.603 回答