首页 > 解决方案 > ArgumentCountError 函数 1 的参数太少,正好传入 9 个

问题描述

我在 codeigniter 上有以下错误

消息:函数 ManageSupplierfull::updatesupplier() 的参数太少,在第 532 行的 C:\Program Files (x86)\Ampps\www\codetest\system\core\CodeIgniter.php 中传递了 1 个,预期正好 9 个

我的控制器ManageSupplierfull.php

public function updatesupplier($name,$email,$phone,$company,$address,$city,$region,$country,$postbox) {


   $result['data']=$this->NewSuppliermodel->updaterecords($get['sid']);
  if($this->input->post('update'))
    {

    $name=$this->input->post('name');
    $email=$this->input->post('email');
    $phone=$this->input->post('phone');
    $company=$this->input->post('company');
    $address=$this->input->post('address');
    $city=$this->input->post('city');
    $region=$this->input->post('region');
    $country=$this->input->post('country');
    $postbox=$this->input->post('postbox');
    $result['data']=$this->NewSuppliermodel->updaterecords($name,$email,$phone,$company,$address,$city,$region,$country,$postbox);

   $this->session->set_flashdata('msg', 'Updated Successfully!');
    }

  }

我的模型NewSuppliermodel.php

public function updaterecords($name,$email,$phone,$company,$address,$sid,$city,$region,$country,$postbox)
  {
  $query=$this->db->query("update suppliers SET name='$name',email='$email',phone='$phone',company='$company',address='$address',city='$city',region='$region',country='$country',postbox='$postbox' where sid='".$sid."'");
   return $query->result();
  } 

我的观点

 <?php
  $i=1;
  foreach($data as $row)
  {
    ?>
    <form class="form" method="post" action="<?php echo base_url('app/managesupplierfull/updatesupplier/'.$row->sid) ?>">

                                            <div class="row">
                                                <div class="col">
                                                    <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="simpleinput">Name</label>
                                                        <div class="col-lg-10">
                                                            <input type="text" class="form-control" id="simpleinput" name="name"  value="<?php echo $row->name; ?>" required
                                                               >
                                                        </div>
                                                    </div>


                                                    <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="example-email">Email</label>
                                                        <div class="col-lg-10">
                         <input type="email" id="example-email" name="email"
                                      value="<?php echo $row->email; ?>"                          class="form-control" required="">
                                                        </div>
                                                    </div>
                                                  <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="simpleinput">Company</label>
                                                        <div class="col-lg-10">
                                                            <input type="text" class="form-control" id="simpleinput" name="company" value="<?php echo $row->company; ?>"
                                                               >
                                                        </div>
                                                    </div>
 <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="simpleinput">Phone</label>
                                                        <div class="col-lg-10">
                                                            <input type="text" class="form-control" id="simpleinput" name="phone" value="<?php echo $row->phone; ?>"
                                                               >
                                                        </div>
                                                    </div>

                                                    <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="example-textarea">Address</label>
                                                        <div class="col-lg-10">
                                                            <textarea class="form-control" rows="5"
                                                             name="address" placeholder="" id="example-textarea"><?php echo $row->address; ?></textarea>
                                                        </div>
                                                    </div>

                                       <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="simpleinput">City</label>
                                                        <div class="col-lg-10">
                                                            <input type="text" class="form-control" id="simpleinput" name="city" value="<?php echo $row->city; ?>"
                                                               >
                                                        </div>
                                                    </div>
                                                   <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="simpleinput">Region</label>
                                                        <div class="col-lg-10">
                                                            <input type="text" class="form-control" id="simpleinput" name="region" value="<?php echo $row->region; ?>"
                                                               >
                                                        </div>
                                                    </div>


                                                   <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="simpleinput">Country</label>
                                                        <div class="col-lg-10">
                                                            <input type="text" class="form-control" id="simpleinput" name="country" value="<?php echo $row->country; ?>"
                                                               >
                                                        </div>
                                                    </div>
                                                    <div class="form-group row">
                                                        <label class="col-lg-2 col-form-label"
                                                            for="simpleinput">Post Box</label>
                                                        <div class="col-lg-10">
                                                            <input type="text" class="form-control" id="simpleinput" name="postbox" value="<?php echo $row->postbox; ?>"
                                                               >
                                                        </div>
                                                    </div>
                                                    <?php } ?>
   <button type="submit" name="update" class="btn btn-primary">Update</button>
                                                </div>

                                            </div>



                                        </form>

我在另一个视图中有一个表格,当我单击更新按钮时,它会打开一个新页面,并且此表单按 id 显示现有数据,当单击更新时,它应该只在当前 ID 中,但参数没有传递。

标签: phpcodeigniter

解决方案


尝试像这样更新控制器:

public function updatesupplier($sid) { // changed & removed unused parameters

  if($this->input->post('update'))
    {

    $name=$this->input->post('name');
    $email=$this->input->post('email');
    $phone=$this->input->post('phone');
    $company=$this->input->post('company');
    $address=$this->input->post('address');
    $city=$this->input->post('city');
    $region=$this->input->post('region');
    $country=$this->input->post('country');
    $postbox=$this->input->post('postbox');
    $result['data']=$this->NewSuppliermodel->updaterecords($name,$email,$phone,$company,$address,$sid,$city,$region,$country,$postbox); // added missing $sid parameter

   $this->session->set_flashdata('msg', 'Updated Successfully!');
    }

  }

推荐阅读