【问题标题】:security component issue in cakephpcakephp 中的安全组件问题
【发布时间】:2013-09-22 20:27:36
【问题描述】:

在我的应用程序中,我使用安全组件并在应用程序控制器中定义,如下所示

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

【问题讨论】:

    标签: cakephp-2.0 cakephp-1.3 cakephp-2.1 cakephp-2.3


    【解决方案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
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多