【问题标题】:cakePHP 2.2: CFSR Security Component with Ajax loaded Views and ElementscakePHP 2.2:具有 Ajax 加载视图和元素的 CFSR 安全组件
【发布时间】:2013-06-19 11:57:29
【问题描述】:

我正在尝试让 CakePHP 的用于 CSFR 保护的安全组件与 AJAX 一起使用。
我有我的ArtistsDates-Controller(用于保存艺术家/DJ 的所有演出日期),其中包含addedit() - 视图。

这个视图是通过 jQuery AJAX 加载到一个 jQuery Modalbox 中的。 (SimpleModal)

 function artist_dates(request){
   .
   .
    if(request == 'load'){
        $.ajax({
            type: 'post',
            url: $('base').attr('href') + '/artist_dates/addedit/'+artist_id,
            success: function(html){

                $('#dialog').html(html);
                $('#dialog').modal({
                    modal: false,
                    maxHeight:'500px',
                    minHeight:500,
                    minWidth:750,
                });
            }
        });
    }
   .
   .
 }

在此视图中,我的表单呈现为 addedit_daterow_form - 元素。这个元素要么用数据调用,要么以“新”模式调用。如果提供了数据,该元素将显示数据并包含一个隐藏编辑表单。如果在“NEW”模式下调用它,它会返回一个空表单。因此,为 ArtistDate - 模型中的每个数据行呈现此元素(+1 用于添加新的!)

(这是视图的截图:http://i.stack.imgur.com/Ye10v.png)

Security-组件包含在ArtistDatesController 中。不幸的是,$this->Form->request->params 既不包含 [_Token] 在 addedit- 视图中也不在 addedit_daterow_form- 元素中 - 我是否必须在我的 jQuery-AJAX-Function 中更改某些内容?

-- 编辑 1: 这就是我的表单代码的样子:

<?php echo $this->Form->create('ArtistDate', array('controller' => 'artist_dates','action' => 'addedit', 'id' => 'artistDateForm_'.$date_nr)); ?>
        <?php echo pr($this->Form->request->params); ?>
        <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.id',array('type' => 'hidden', 'value' => $date['ArtistDate']['id'])); ?>
        <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.artist_id',array('type' => 'hidden', 'value' => $date['ArtistDate']['artist_id'])); ?>

        <div class="date">
            <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.date', array('type' => 'text','label' => 'Date <span style="font-weight:normal; float:right;">[DD.MM.YYYY]</span>','value' => (!empty($date['ArtistDate']['date']) ? date('d.m.Y',strtotime($date['ArtistDate']['date'])) : ''))); ?>
            <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.date_end', array('type' => 'text','label' => 'Enddate <span style="font-weight:normal; float:right;">[DD.MM.YYYY]</span>','value' =>(!empty($date['ArtistDate']['date_end']) ? date('d.m.Y',strtotime($date['ArtistDate']['date_end'])) : ''))); ?>
        </div>
        <div class="venue">
            <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.venue', array('type' => 'text','value' => $date['ArtistDate']['venue'])); ?>
            <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.city', array('type' => 'text','value' => $date['ArtistDate']['city'])); ?>
        </div>
        <div class="link">
            <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.venuelink', array('type' => 'text','label' => 'Link <span style="font-weight:normal; float:right;">Venue</span>','value' => $date['ArtistDate']['venuelink'])); ?>
            <?php echo $this->Form->input('ArtistDate.'.$date_nr.'.ticketslink', array('type' => 'text','label' => 'Link <span style="font-weight:normal; float:right;">Tickets</span>','value' => $date['ArtistDate']['ticketslink'])); ?>
        </div>
        <div class="actions">
            <?php echo $this->Html->link('','',array('class' => 'buttonsave','onclick' => "artistdate_handling('".$date_nr."','save'); return false;", 'style' => $display_exists, 'escape' => false, 'title' => 'Save')); ?>               
            <?php echo $this->Html->link('','',array('class' => $approveclass, 'onclick' => "artistdate_handling('".$date_nr."','confirm'); return false;", 'style' => $display_exists, 'escape' => false, 'title' => 'Confirm Show')); ?>
            <?php echo $this->Html->link('','',array('class' => 'buttondelete','onclick' => "artistdate_handling('".$date_nr."','delete'); return false;", 'style' => $display_exists, 'escape' => false, 'title' => 'Delete Show')); ?>
            <?php echo $this->Html->link('','',array('class' => 'buttonadd','onclick' => "artistdate_handling('".$date_nr."','add'); return false;", 'style' => $display_new, 'escape' => false, 'title' => 'Add Show')); ?>
        </div>
        <div style="clear:both"></div>
    <?php echo $this->Form->end(); ?>

提前非常感谢!

【问题讨论】:

    标签: security jquery cakephp simplemodal cakephp-2.2


    【解决方案1】:

    想出了一种工作方式。
    使用

     $.ajax({
        type: 'get'
     .
     .
     });
    

    返回一个包含令牌的表单。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-16
      • 2017-07-17
      相关资源
      最近更新 更多