2017-10-04 199 views
0

我無法將ID值從視圖傳遞到控制器。傳遞一個id值從視圖到codeigniter中的控制器

查看頁:

<form> 
    First name; <input type="text" name="firstname" id="firstname" value=""> 
    Last name:<input type="text" name="lastname" name="lastname" value="">  
<a class="btn btn-info" href="<?php echo base_url();?>index.php/Inventory/issue/<?php echo $value->firstname; ?>" >PRINT</a> 
</form> 

控制器:

public function issue($firstname){ 
    $this->Inventory_model->pick_Issue_model($firstname); 
} 
+0

請先閱讀http://www.codeigniter.com/user_guide/general/views.html#adding-dynamic-data-to-the-view – user4419336

+0

首先從您的url中刪除index.php –

回答

0
<a class="btn btn-info" href="<?php echo base_url();?>index.php/Inventory/issue?firstname=<?php echo $value->firstname; ?>" >PRINT</a> 

現在控制器,你可以檢索名字爲:

$_GET['firstname']; 
+0

如果它適合你,請給我一個upvote,因爲我想恢復我的問題提問能力。 –

+0

顯示:遇到的php錯誤 –

+0

現在刪除echo base_url() 之後的問號現在一旦你在url中定義一個參數只能檢索它的方法是使用$ _GET –

0

而是通過URL傳遞變量, POST表單上的值提交..

您的形式更改爲

<form action="<?php echo base_url();?>index.php/Inventory/issue/" method="POST"> 
    First name; <input type="text" name="firstname" id="firstname" value=""> 
    Last name:<input type="text" name="lastname" name="lastname" value="">  
<button type="submit" class="btn btn-info" >PRINT</button> 
</form> 

在你控制器

public function issue(){ 
    $firstname = $this->input->post('firstname'); 
    $this->Inventory_model->pick_Issue_model($firstname); 
} 
+0

在窗體中我已經使用樹按鈕,其中一個保存按鈕使用type = submit.now我想打印PDF文件....並在URL中調用herf = url .pass id值 –

0

也許你可以在表單中的控制器錯誤的方式,因爲使用隱藏域

<input type="hidden" name="fname" value="<?=$value->firstname?>"> 

然後

public function issue(){ 
    $postdata = $this->input->post(); 
    $firstname = $postdata['fname']; 

    $this->Inventory_model->pick_Issue_model($firstname); 
} 
0

您發送表單它沒有提交類型, 但是如果你想通過你的dat一個在你的代碼的鏈接像一條線

<a class="btn btn-info" href="<?php echo base_url();?>index.php/Inventory/issue/<?php echo $value->firstname; ?>" >PRINT</a> 

您將數據發送到控制器命名庫存以功能命名問題與參數FIRST_NAME 所以現在你可以看到下面的代碼闡述如何獲取數據到控制器

public function issue($firstname){ 
    $fname = $firstname; //Do this 
    $this->Inventory_model->pick_Issue_model($fname); // pass variable here 
} 

$firstname店golam而這個名字您發送到控制器的功能,但在這裏,你是直接調用模型$this->Inventory_model->pick_Issue_model($firstname)因此模型無法識別其中日是$firstname來自

相關問題