hey Chris,

I'm assuming that you will pass the chosen number of order lines back
to your controller when the form is submitted yes?

If so, why couldn't you do something like :

$this->data['OrderLine']['order_id'] = $order_id;
for ($i = 0; $i < $number_order_lines; $i++)
{
    $this->Order->OrderLine->create();
    $this->Order->OrderLine->save($this->data['OrderLine']);
}

HTH,
mikee

On 03/02/07, cdomigan <[EMAIL PROTECTED]> wrote:
>
> Hi there,
>
> I've done a search and can't find anything that answers this question,
> so am hoping someone can help.
>
> Basically I have an Order model that hasMany OrderLine's in it. I have
> a view that lets me specify the Order and 'n' number of OrderLines all
> on one page (with a little help from some javascript).
>
> For eg,
>
> // My view
> <h2>Order info</h2>
> Reference <input name="data[Order][reference]" />
> Date required <input name="data[Order][required]" />
>
> <h2>Products to order</h2>
> 1 <input name="data[OrderLine][qty][]" /><input name="data[OrderLine]
> [description][]" />
> 2 <input name="data[OrderLine][qty][]" /><input name="data[OrderLine]
> [description][]" />
> 3 <input name="data[OrderLine][qty][]" /><input name="data[OrderLine]
> [description][]" />
> etc...
>
> So what I want is to save the Order (no problem) and then save 'n'
> number of OrderLines as well. As you can see  I've named my OrderLines
> with a [] at the end, so that I get an array of values to pass to my
> controller.
>
> What I'm wondering is if CakePHP will let me do something like this:
>
> // In my controller
>
> function placeOrder() {
>   if (!empty($this->data)) {
>     if ($this->Order->save($this->data)) {
>       $order_id = $this->Order->getLastInsertId();
>       $this->data['OrderLine']['order_id'] = $order_id;
>       $this->Order->OrderLine->save($this->data);
>     }
>   }
> }
>
> On the last line of that code I want it to loop through all my
> submitted OrderLine's and save them with an order_id of $order_id.
> Anyone know how I can do this, and what the required syntax is?
>
> Cheers,
>
> Chris
>
>
> >
>

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