I have a model relationship with Product hasmany Page. When I add a new product and then go to the view, i can add a new prodpage to that product. However, clicking the link does not pass the current Product id to the prodpages/add page. I would like it to do that so that when you go to add the prodpage the associated Product ID is already selected based on the previous product you were viewing.
I think it comes down to editing the link in the Product View and passing the id to append after the prodpages/add/. is that correct? here it is:
<?php echo $this->Html->link(__('New Prodpage'), array('controller' => 'prodpages', 'action' => 'add'));?> </li>
How can I include the product id to that?
when It comes to the Prodpages controller.. here is what I got so far for the add function..
public function add($product_id) {
if ($this->request->is('post')) {
$this->Prodpage->create();
if ($this->Prodpage->save($this->request->data)) {
$this->Session->setFlash(__('The prodpage has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The prodpage could not be saved. Please, try again.'));
}
}
$products = $this->Prodpage->Product->find('list');
$this->set(compact('products'));
$this->data['Prodpage']['product_id'] = $product_id;
}
will that work for the controller?
Yep, just add it to your link
Your missing more of your view, but this assumes that your view has a variable
$product_id.