繁体   English   中英

Codeigniter无法从输入中获取价值

[英]Codeigniter doesn't take value from input

我的codeigniter有问题:
我认为
<input type="text" name="code" style="width:310px;">
我的控制器
$code = $this->input->get('code');
在我从模型中调用函数后:
$this->model->add($code);
问题是codeigniter在控制器中不$this->model->add('342432'); (我用$this->model->add('342432');进行了测试$this->model->add('342432');它是$this->model->add('342432');所以我认为问题出在视图和控制器之间。
有没有人解决? 谢谢!。

这取决于表单提交方法。

从您的代码中: $code = $this->input->get('code'); get

如果您想使用post方式的形式,请使用

$code = $this->input->post('code');

如果您在Codeignitor中使用get方法,请

$config['allow_get_array']      = TRUE; 

在您的config.php文件中

$config['allow_get_array'] is FALSE(default is TRUE), destroys the global GET array.

视野中

<form action="<?php echo base_url()?>/conteroller/method" method="post">
    <input type="text" name="code" style="width:310px;"> 
    <input type="submit" name="submit" > 
</form>

在控制器中

if(isset($_POST['submit']))
{
    $code = $_POST['code'];
    $result =  $this->model_name->add($code);
    print_r($result);//to check the output
}

注意事项

  1. 使用config/autoload.php base_url()函数

      $autoload['helper'] = array('url'); 
  2. __construct控制器负载模型中

      public function __construct() { parent::__construct(); $this->load->library('session'); $this->load->model('Model_name');//Ex: Product_Model } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM