0

やあ、

私はjq_link_to_remote関数を使用して、コメントへの回答を行うためのフォームをdivにロードしています(Facebookのように)。私の問題は、このフォームを「social / response / id / 14」のように呼んでいることです。ここで、idは親の意見を含んでいます。フォームの非表示フィールドにsetValueを設定する関数を作成します。

それでは、なぜ直接'social / reply / id / 14'を呼び出そうとすると、正しく値が割り当てられ、jq_linkで呼び出した場合は呼び出されないのですか?フィールドの設定値よりも関数の入力として渡された値の「エコー」を実行すると、正常に動作します。

ありがとう。

フォームコード。

public function setDefaultEntityId($id_response=0)
  {
   if($id_response!=0){
     $this->setDefault('sf_opinion_id',$id_response);   
   }
   $this->configure();
  } 

テンプレート意見

<?php echo jq_link_to_remote('opinar', 
                 array(
                        'update' => 'respuesta_hidden_'.$opinion->getId(), 
                         'url'  => 'social/responder?id_response='.$opinion->getId()),array('rel' => 'nofollow','class' =>'mini')

); ?>

アクションレスポンダー

$this->form = new OpinionResForm();

$this->form->setDefaultEntityId($request->getParameter('id_response'));

// formulario opiniones
if($request->isMethod(sfRequest::POST))
{
    $this->form->bind($request->getParameter($this->form->getName()));
    if ($this->form->isValid()) {
    $opinion = $this->form->save();  
    }
}

そして最後に、生成されたコードの例...

<a onclick="jQuery.ajax({type:'POST',dataType:'html',success:function(data, textStatus){jQuery('#respuesta_hidden_1').html(data);},url:'/sfproject/zampalo/web/frontend_dev.php/social/responder/id_response/1'}); return false;" href="#" class="mini" rel="nofollow">opinar</a>

それがお役に立てば幸いです...:)

4

1 に答える 1

0

うーん、きれいに見えます。何が問題なのかわかりません。ただし、次の形式でこれを行う理由がわかりません。

if($id!=0){
  $this->setDefault('id_elemento',$id);
}
if($id_response!=0){
  $this->setDefault('id_elemento',$id_response); 
}

id_elemento のデフォルトを 2 回設定しています。$id と $id_response が 0 でない場合、id_elemento が最初に $id に設定され、次に $id_response が設定されます...これは正しくないように聞こえます。

于 2010-04-28T16:16:03.743 に答える