1

私はページを持っています:my-account/my-templates/view/1-単にアイテムを表示するためにのidフィールドを使用します1

私がやりたいのは、このアイテムのすべての値を取得して新しいアイテムを作成するコピーアクションを作成することです。

私はlink_to()以下を保持するを持っています:

<?php echo link_to('Copy', '@copy_template', array('id' => $template->getId())); ?>

テンプレートのIDを渡します。

コピーアクションでこのIDにアクセスできますか?

編集:

行動:

public function executeViewTemplate(sfWebRequest $request)
{
  $this->template = Doctrine_Core::getTable('UserTemplate')->getUserTemplate($request->getParameter('id'));
}

public function executeTemplateCopy(sfWebRequest $request)
{
   $this->id = $request->getParameter('id');
   // get the passed template id 
}

テンプレート:

viewTemplateSuccess.php

<?php echo link_to('Copy', '@copy_template', array('id' => $sf_request->getParameter('id'), 'class'=>'button green')); ?>

templateCopySuccess.php

<?php echo "ID". $id;?> --> doesn't return the passed id
4

2 に答える 2

1

アクションでは、以下を使用してパラメーターを取得できます。

$id = $request->getParameter('id');

たとえば、次のアクションがある場合:

public function executeCopyTemplate(sfWebRequest $request)
{
  $id = $request->getParameter('id');
}

そしてテンプレートから:

<?php $id = $sf_request->getParameter('id') ?>

あなたの場合:

<?php echo link_to('Copy', '@copy_template?id='.$sf_request->getParameter('id')); ?>
于 2012-11-15T16:00:54.803 に答える
0

link_to関数の最後にある配列は、classやidなどのHTML属性を変更します。通常はURLパラメータを渡しません。これは機能します:

<?php echo link_to('Copy', '@copy_template?id='. $template->getId(), array()); ?>
于 2012-11-15T16:13:41.353 に答える