Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/262.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将id值从视图传递到codeigniter中的控制器_Php_Codeigniter - Fatal编程技术网

Php 将id值从视图传递到codeigniter中的控制器

Php 将id值从视图传递到codeigniter中的控制器,php,codeigniter,Php,Codeigniter,我无法将id值从视图传递到控制器 查看页面: <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 ba

我无法将id值从视图传递到控制器

查看页面:

<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>

不要通过url传递变量,而是在表单提交中发布值

把你的表格改成

<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>

您可以使用codeigniter的URI类

public function issue(){
   $firstname = $this->uri->segment(3);
   $this->Inventory_model->pick_Issue_model($firstname);
}

作为参考:

也许您可以在表单中使用隐藏字段

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

您发送表单的方式错误,因为它没有提交类型, 但如果您想像代码中的一行那样从链接传递数据

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

假设
$firstname
存储golam和发送给控制器函数的名称,但这里您直接调用model
$this->Inventory\u model->pick\u Issue\u model($firstname)
因此模型无法识别此
$firstname
来自何处

首先阅读此内容从您的url中删除index.php如果它对您有效,请放弃投票,因为我想恢复我的提问能力。在echo base_url()之后删除问号现在,在url中定义参数后,检索该参数的唯一方法是使用$\u GETor,也可以使用form action,使用方法POST定义url,并在controlelr函数中使用:$\u POST['firstname'];在表单中,我已经使用了树按钮,其中一个保存按钮使用type=submit。现在我想打印pdf文件…并调用herf=url。在url中传递id值
public function issue(){
  $firstname = $this->input->post('firstname');
   $this->Inventory_model->pick_Issue_model($firstname);
}
public function issue(){
   $firstname = $this->uri->segment(3);
   $this->Inventory_model->pick_Issue_model($firstname);
}
<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);
}
<a class="btn btn-info" href="<?php echo base_url();?>index.php/Inventory/issue/<?php echo $value->firstname; ?>" >PRINT</a>
public function issue($firstname){
   $fname = $firstname;  //Do this
   $this->Inventory_model->pick_Issue_model($fname); // pass variable here
}