[英]CodeIgniter how to give action url for view page
我有用於顯示產品的CodegIniter系統。 通過以下網址執行產品查看頁面時
localhost/project/index.php/product/view/102
我想在此頁面中添加一個選項來為特定產品添加評論,但是我該如何給
$data['action'] = site_url('product/prodcutView');
這是我到目前為止嘗試過的,但是沒有保存價值,我的動作網址不正確,請指教。
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);
}
您可以嘗試使用uri細分,以確保您的網站網址鏈接正確無誤,並與您的網址相匹配。
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);
}
您可以將其存儲在數組中,然后給該var像這樣查看$this->load->view('product_view',$data);
這里$ data在您的情況下包含prod_id。 像這樣$data['prod_id']=$result[0]['prod_id'];
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.