2010-08-22 3 views
5

Sto costruendo un sito che richiede più moduli per lo stesso modello in vari numeri su un'unica pagina. Queste forme appartengono ad un oggetto con un id. Attualmente, dal momento che non riesco a capire come modificare gli ID dei moduli, sono bloccato da una serie di id duplicati.Come faccio a utilizzare l'aiuto di forma 'create' di cakePHP con un ID personalizzato?

Sto cercando un modo per aggiungere l'ID oggetto all'id del modulo in modo che non siano non validi. Preferisco scrivere il mio javascript quindi non userò l'helper ajax.

<?php 

/** 
* This is a simplified example of what I am trying to do. 
*/ 

?> 

<div id="objects"> 
    <?php foreach($objects as $object): ?> 
    <div class="object"> 
     <?php echo "this is object {$object['Object']['id']}"?> 
     <?php 
     //The following element would show a number of comments the object owns 
     echo $this->element('object_comments_loop', array('comments' => $object['Object']['Comments']); 
     ?> 
     <div class="comment"> 
     <?php 
      //each object has a form. 
      //TODO: this is where the id issue comes into play. 

      echo $form->create('Comment', array('url' => array('controller' => 'comments', 'action' => 'createComment')); 
      echo $form->hidden('object_id', array('value' => $object['Object']['id'])); 
      echo $form->input('comment_body', array('label' => __('comment', true), 'type' => 'text')); 
      echo $form->end(__('comment_submit', true)); 
     ?> 
     </div> 
    </div> 
    <?php endforeach; ?> 
</div> 

risposta

4
echo $form->create('Comment', array('url' => array('controller' => 'comments', 'action' => 'createComment'), "id" => "form_".$object['Object']['id'])); 

Questo dovrebbe fare il trucco, credo.

EDIT:

Dopo la revisione, questo è ciò che ho usato per ottenere quello che stavi chiedendo:

echo($form->create('Comment', array('action' => 'createComment', "id" => "form_".$object['Object']['id']))); 
+0

fammi guardare sopra il vostro codice, quindi, perché questo funziona bene per me: create ("Opzione", array ("id" => "Test")))??> Vedere: codeacula.com e visualizzare la fonte. – Codeacula

+0

Aggiornato. Questa è la forma che funziona per me. Se non fa per te, è al di là delle mie conoscenze con ciò che viene fornito. – Codeacula

+0

ah scusa. Funziona. Ho avuto un momento di vista di stupidità. Stavo guardando uno degli input all'interno del modulo, non la forma stessa. Wow, mi sento sciocca. Grazie per l'aiuto. –