【问题标题】:Copy action in symfony 1.4symfony 1.4 中的复制操作
【发布时间】:2011-08-07 21:08:17
【问题描述】:

我还需要在 symfony 中创建一个复制操作。我已经看过这些问答:symfony 1.4: creating "Copy" action。它似乎工作正常,但是当我尝试保存这些错误消息时:“csrf token: CSRF attack detected”。我估计是因为我不知道在哪里更改表单属性操作。

非常感谢任何帮助!

这是我的代码:

actions.class.php:

class eventActions extends autoEventActions {

  public function executeCopy(sfWebRequest $request)
  {

    $this->form = new EventCopyForm($this->getRoute()->getObject());
    $this->event = $this->form->getObject();
    $this->setTemplate('copy');
  }

  public function executeUpdatecopy(sfWebRequest $request)
  {
    $this->form = new EventCopyForm($this->getRoute()->getObject());
    $this->processForm($request, $this->form);
    $this->setTemplate('copy');
  }
}

EvenCopyForm.class.php:

class EventCopyForm extends EventForm {

  public function doSave($conn = null)
  {
    $this->updateObject();
    $event = $this->getObject()->copy();
    $event->save();
  }  
}

copySuccess.php:

<?php use_helper('I18N', 'Date') ?>
<?php include_partial('event/assets') ?>

<div id="sf_admin_container">
  <h1><?php echo __('Copy Event', array(), 'messages') ?></h1>

  <?php include_partial('event/flashes') ?>

  <div id="sf_admin_header">
    <?php include_partial('event/form_header', array('event' => $event, 'form' => $form, 'configuration' => $configuration)) ?>
  </div>
  <div id="sf_admin_content">
    <?php include_partial('event/form', array('event' => $event, 'form' => $form, 'configuration' => $configuration, 'helper' => $helper)) ?>
  </div>
  <div id="sf_admin_footer">
    <?php include_partial('event/form_footer', array('event' => $event, 'form' => $form, 'configuration' => $configuration)) ?>
  </div>
</div>

【问题讨论】:

    标签: copy action symfony-1.4


    【解决方案1】:

    我现在以不同的方式完成了它: + 我将对象作为数组获取:

    $original->toArray(false);
    
    • 然后取消设置id:

      未设置($originalValues['id']);

    • 制作一个我保存的复制对象:

      $copy = new Event(); $copy->fromArray($originalValues); $copy->保存();

    这对我来说很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      相关资源
      最近更新 更多