You will have to create the inputs the old fashioned way, and create
the empyer records as an array that you can loop over when posted
back.

In the controller function use $this->set('formerEmployers', $this-
>FormerEmployer->findAllByApplicantId($applicant_id));

Then in the view, make sure you include FormerEmplyee id if it is an
edit and do something like

<?php for ($i=0; $i < count($formerEmployers); $i++): ?>
  <input type='text' name='data[FormerEmployers][<?= $i; ?>][name]'
value='<?= $formerEmplyers[$i]['FormerEmployer']['name']; ?>" />
  <input type='hidden' name='data[FormerEmployers][<?= $i; ?>][id]'
value='<?= $formerEmplyers[$i]['FormerEmployer']['id']; ?>" />
<?php endfor; ?>


Then in the post back you can loop over the records with

foreach ($this->data['FormerEmployers'] as $employer){
  $this->FormerEmployer->create(); // you need this line to stop the
model repeatedly saving over the initial record
  $toSave = array("FormerEmployer" => $employer);
  $this->FormerEmployer->Save($toSave);
}

Geoff
--
http://lemoncake.wordpress.com
On Jul 26, 7:42 am, chewie124 <[EMAIL PROTECTED]> wrote:
> Hi All -
> I'm have a job-board app that has a Resume model which hasMany
> FormerEmployer models (like for employment history).  There's plenty
> of discussion on how to save the data on the controller side (at
> least, that I've been able to find), but my question is, is how do you
> build up the form, so when I hit submit, it will send  the Resume and
> the associated FormerEmployer (more than one) data fields that I can
> handle back in the controller?
>
> Can somebody fill in the missing pieces for me?
>
> <?php echo $form->input('first_name'); ?>
> <?php echo $form->input('last_name'); ?>
>
> <h2>Former Employers</h2>
> <?php foreach ($this->data['FormerEmployer'] as $employer): // THIS
> ISN'T RIGHT... ?>
> <?php echo $form->input('FormerEmployer.name'); ?>
>
> <?php endforeach; ?>
>
> I'm using cake 1.2...
>
> Thanks,
> Rich


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to