在symfony 1.4中复制操作

时间:2011-08-07 21:08:17

标签: copy action symfony-1.4

我还需要在symfony中创建一个复制动作。我已经看过这些问题并回答:symfony 1.4: creating "Copy" action。它似乎工作正常,但当我尝试保存一个获取这些错误消息:“csrf令牌:检测到CSRF攻击”。我认为这是因为我不知道在哪里更改表单属性操作。

非常感谢任何帮助!

这是我的代码:

的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>

1 个答案:

答案 0 :(得分:0)

我现在以不同的方式做到了: +我将对象作为数组:

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

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

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

    $ copy = new Event(); $禁止复制&GT; fromArray($ originalValues); $禁止复制&GT;保存();

这对我来说很好。