【问题标题】:codeigniter checkbox implode function errorcodeigniter复选框内爆功能错误
【发布时间】:2016-10-07 00:36:19
【问题描述】:

这是我的观点

<input type="text" name="name" class="form-control" placeholder="name" />
<div class="col-sm-12">
    <select name="speciality"  class="form-control" required >
        <option value="" selected="selected" >Liste speciality</option>
        <option value="ag" >spec1</option>
        <option value="al" >spec2</option>
        <option value="pvc">spec3</option>
        <option value="MEDC">spec4</option>
    </select>
</div>

<div class="col-sm-9">
    <label class="checkbox-inline">
        <input type="checkbox"  value="parquet" name="products[]">
        product1
    </label>

    <label class="checkbox-inline">
        <input type="checkbox"  value="fplancher" name="products[]">
        product2
    </label>

    <label class="checkbox-inline">
        <input type="checkbox"  value="fauxplafonddem" name="products[]">
        product3
    </label>

    <label class="checkbox-inline">
        <input type="checkbox"  value="cloison" name="products[]">
        product4 
    </label>

    <label class="checkbox-inline">
        <input type="checkbox"  value="cloisonamovible" name="products[]"> 
        product5 
    </label>

    <div class="bottom">
        <button class="btn btn-primary" name="btnAdd" value="1"  type="submit"> <i class="fa fa-mail-reply-all"> &nbsp;save</i> </button>
        <button class="btn btn-default" type="reset" > <i class="fa fa-ban">&nbsp;cancel</i></button>
    </div>
</div>

这是我的控制器

public function add() {
         $prod=implode(',',$this->input->post('products'));
           $data=array('nomsoc'=>$this->input->post('name'),
                    'specialitesoc'=>$this->input->post('speciality'),
                    'produitssoc'=>$prod);
           if ($this->input->post("btnAdd", false))
            { 
            if($this->SocieteModel->add($data))
                {
                $this->session->set_flashdata('message', 
                '<div class="alert alert-success" role="alert">Société ajoutée avec succès </div>');
                redirect("/societe/");
            } 

       }
    $this->layout->title(' campany Title'); // Set page title
                $this->LoadViewBlocks("societe","","",true,true,true);
                $data["bodyId"]="register-bg";
                $this->layout->view('backend/societe/add', $data);
        }

当我加载视图以添加新的campany时,我收到了错误:

遇到 PHP 错误 严重性:警告消息:内爆():传递的参数无效 行号:41

任何机构都可以帮忙!

【问题讨论】:

  • 如果你使用双引号会发生什么? $prod=implode(",",$this->input->post('products'));
  • 双引号也有同样的问题
  • 您使用相同的方法加载添加视图和保存添加视图?
  • print_r($this->input->post('products'));并在使用 implode 之前查看它是否是一个数组
  • 茯苓在哪里放置 print_r($this->input->post('products')); ?

标签: javascript php html codeigniter


【解决方案1】:
  1. 遇到 PHP 错误 严重性:警告消息:implode():传递的参数无效 行号:41

如果$this-&gt;input-&gt;post('products') 值为空或不是数组,则会出现上述错误。确保你有数组值。

  1. 我已经尝试过您的代码。它工作正常。请通过它。

    我使用了这个视图页面。

    <form action="<?php echo base_url(); ?>index.php/forms/add" method="post"><input type="text" name="name" class="form-control" placeholder="name" />
      <div class="col-sm-12">
         <select name="speciality"  class="form-control" required >
                 <option value="" selected="selected" >Liste speciality</option>
                 <option value="ag" >spec1</option>
                 <option value="al" >spec2</option>
                 <option value="pvc">spec3</option>
                 <option value="MEDC">spec4</option>                     
         </select>
      </div>
        <div class="col-sm-9">
           <label class="checkbox-inline">
             <input type="checkbox"  value="parquet" name="products[]">
              product1</label>
            <label class="checkbox-inline">
             <input type="checkbox"  value="fplancher" name="products[]">    product2</label>
         <label class="checkbox-inline">
         <input type="checkbox"  value="fauxplafonddem" name="products[]">
                    product3</label>
                    </div>
                    <label class="checkbox-inline">
                     <input type="checkbox"  value="cloison" name="products[]">
                                   product4 </label>
                     <label class="checkbox-inline">
                      <input type="checkbox"  value="cloisonamovible" name="products[]"> product5 </label>
         <div class="bottom">
         <button class="btn btn-primary" name="btnAdd" value="1"  type="submit"> <i class="fa fa-mail-reply-all"> &nbsp;save</i> </button>
         <button class="btn btn-default" type="reset" > <i class="fa fa-ban">&nbsp;cancel</i></button>
                    </div>
    
                    </form>
    

在我的控制器中

public function add() {
         $prod=implode(',',$this->input->post('products'));
           $data=array('nomsoc'=>$this->input->post('name'),
                    'specialitesoc'=>$this->input->post('speciality'),
                    'produitssoc'=>$prod);
           print_r($data); exit();
           if ($this->input->post("btnAdd", false))
            { 
            if($this->SocieteModel->add($data))
                {
                $this->session->set_flashdata('message', 
                '<div class="alert alert-success" role="alert">Société ajoutée avec succès </div>');
                redirect("/societe/");
            } 

       }
                $this->layout->title(' campany Title'); // Set page title
                $this->LoadViewBlocks("societe","","",true,true,true);
                $data["bodyId"]="register-bg";
                $this->layout->view('backend/societe/add', $data);
    }

当我使用 print_r($data);它对我来说工作正常。

【讨论】:

  • 当我使用 print_r($data) 时它显示 Array ( [nomsoc] => [specialitesoc] => [produitssoc] => [activitessoc] => [dirigeantsoc] => [telsoc] => [faxsoc] => [ville] => [adressesoc] => [facebooksoc] => [twittersoc] => [gplussoc] => [linkedinsoc] => [youtubesoc] => [emailsoc] => )
  • 您是否更改了视图文件中的任何内容。
  • input type="checkbox" value="cloisonamovible" name="products[]"> product5 放开标签。
  • 存在于我的视野中,我没有任何改变
  • 您是否在产品复选框中添加了开放标签。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-16
  • 1970-01-01
  • 2015-06-11
相关资源
最近更新 更多