2012-06-14 101 views
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; 
    } 

會爲控制器的工作?

回答

2

沒錯,只需將其添加到您的鏈接

echo $this->Html->link(__('New Prodpage'), array(
    'controller' => 'prodpages', 
    'action' => 'add', 
    $product_id 
)); 

你缺少更多的觀點,但這個假定你的觀點具有可變$product_id

+0

謝謝。作品! – thindery

相關問題