2015-04-22 97 views
0

我有用於顯示產品的CodegInitor系統。當一個產品視圖頁面通過URL像CodeIgnitor如何爲瀏覽頁面提供操作url

localhost/project/index.php/product/view/102 

執行我想補充一個選項,以增加對特定產品的評論在此頁面,但我怎麼給

$data['action'] = site_url('product/prodcutView'); 

這是我有嘗試到目前爲止,但它沒有保存價值,我tihnk行動url不正確,請諮詢。

function addComment() { 

    // set common properties 
    $data['title'] = 'Add new comment'; 
    $data['action'] = site_url('/product/ProductView'); 


    // set empty default form field values 
    $this -> _set_fields(); 
    // set validation properties 
    $this -> _set_rules(); 

    // run validation 
    if ($this -> form_validation -> run() == FALSE) { 

     log_message('debug', 'comment save failed.'); 

    } else { 
     // save data 
     $comment = array(
     'product_id' => $this -> input -> post('product_id'), 
     'comment' => $this -> input -> post('comment'), 
     'review' => $this -> input -> post('review'), 
     ); 
     $category_id = $this -> Comment_model -> save($comment); 


    } 

    // load view 
    $this -> load -> view('/product/ProductView', $data); 
} 
+0

你得到的任何錯誤? –

+0

@HardikBhavsar:不,它只是刷新頁面 –

+0

@HardikBhavsar:如何將行動提供給特定的產品ID頁面。請指教 –

回答

0

你可以嘗試使用uri段確保你的網站url鏈接是正確的,並匹配你在url中的內容。

localhost/project/index.php/product/view/102 

測試回顯出$this->uri->segment(3)並查看顯示的數字。

if ($this->uri->segment(3) == FALSE) { 
    $data['action'] = site_url('product/view'); 
} else { 
    $data['action'] = site_url('product/view') .'/'. $this->uri->segment(3); 
} 
0

您可以將其存儲在陣列並給予VAR查看這樣$this->load->view('product_view',$data); 這裏$數據在你的情況包含PROD_ID。 這樣的$data['prod_id']=$result[0]['prod_id'];