0
我与产品hasmany页有一个模型关系。当我添加新产品,然后转到视图时,我可以为该产品添加新的产品页面。但是,点击该链接不会将当前的产品ID传递到产品/添加页面。我希望这样做,以便当您添加产品页时,根据您正在查看的以前的产品已经选择了关联的产品ID。包含在URL中的ID传递给另一个模型
我认为这归结于编辑产品视图中的链接并传递该id以在prodpages/add /后追加。那是对的吗?这里是:
<?php echo $this->Html->link(__('New Prodpage'), array('controller' => 'prodpages', 'action' => 'add'));?> </li>
我该如何包含产品ID?
,当涉及到Prodpages控制器..这里是我走到这一步,为add函数..
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;
}
会为控制器的工作?
谢谢。作品! – thindery