dongwei1954 2018-10-04 16:23
浏览 100

遇到未捕获的异常类型:ArgumentCountError

Please help me, I cannot access my code it always shows the error:

An uncaught Exception was encountered

Type: ArgumentCountError

Message: Too few arguments to function Gallery::edit(), 1 passed in C:\xampp\htdocs\eatsoc\system\core\CodeIgniter.php on line 532 and exactly 2 expected

Filename: C:\xampp\htdocs\eatsoc\application\controllers\backend\Gallery.php

Line Number: 53

Backtrace:

File: C:\xampp\htdocs\eatsoc\index.php

Line: 315

Function: require_once

But, in my other code the code works fine...

This is the code:

Controller: Gallery.php

class Gallery extends CI_Controller {

//Load Model
public function __construct()
{
    parent::__construct();
    $this->load->model('backend/Gallery_model');
    $this->load->library('upload');
}
//Halaman Utama
public function index()
{
    $gallery = $this->Gallery_model->listing();
    $data = array('title' => 'Data Gallery ('.count($gallery).')',
                  'gallery'  => $gallery,
                  'isi'   => 'backend/gallery/list');
    $this->load->view('backend/layout/wrapper', $data, FALSE);
}    

//Halaman Tambah
public function tambah(){
    //Validasi
    $valid=$this->form_validation;

    $valid->set_rules('tittle', 'tittle', 'required',
            array('required'    => 'tittle harus diisi'));

    $valid->set_rules('file', 'file', 'required',
                      array('required' => 'Gambar harus diisi'));

    if($valid->run()===FALSE){
        $data = array('title' => 'Tambah Gallery',
                  'isi'   => 'backend/gallery/tambah');
        $this->load->view('backend/layout/wrapper', $data, FALSE); 
    }else{
        $i= $this->input;
        $data = array('id_gallery' => $i->post('id_gallery'),
                      'tittle' => $i->post('tittle'),
                      'deskripsi'=> $i->post('deskripsi'),
                      'file'=> $i->post('file'),
                     );
        $this->Gallery_model->tambah($data);
        $this->session->set_flashdata('sukses','Data telah ditambah');
        redirect(base_url('backend/gallery'),'refresh');
    }
    //End masuk database
}

//Halaman Edit
public function edit($id_gallery){
    $gallery = $this->Gallery_model->detail($id_gallery);

    //Validasi
    $valid=$this->form_validation;

    $valid->set_rules('tittle', 'tittle', 'required',
                      array('required' => 'tittle harus diisi'));

    if($valid->run()===FALSE){
        $data = array('title' => 'Edit Gallery: '.$gallery->tittle,
                      'gallery'  => $gallery,
                      'isi'   => 'backend/gallery/edit');
        $this->load->view('backend/layout/wrapper', $data, FALSE); 
    } else{
        $i= $this->input;
        $this->Gallery_model->edit($data);
        $this->session->set_flashdata('sukses','Data telah diubah');
        redirect(base_url('backend/gallery'),'refresh');
    }
    //End masuk database
}

//Halaman Delete
public function delete($id_gallery){
    $data = array('id_gallery' => $id_gallery);
    $this->Gallery_model->delete($data);
    $this->session->set_flashdata('sukses', 'Data telah dihapus');
    redirect(base_url('backend/gallery'),'refresh');
} 

}

Model: Gallery_model.php

class Gallery_model extends CI_Model{

public function __construct()
{
    parent::__construct();
    $this->load->database();
}

//Listing
public function listing(){
    $this->db->select('*');  
    $this->db->from('gallery'); 
    $this->db->order_by('id_gallery');
    $query = $this->db->get();
    return $query->result();
}

//Detail
public function detail($id_gallery){
    $this->db->select('*');  
    $this->db->from('gallery'); 
    $this->db->where('id_gallery',$id_gallery); 
    $this->db->order_by('id_gallery');
    $query = $this->db->get();
    return $query->row();
}

// Tambah
public function tambah($data){
    $this->db->insert('gallery', $data);   
}

// Edit
public function edit($id_gallery, $data){
    $this->db->where('id_gallery', $data['id_gallery']);   
    $this->db->update('gallery', $data['id_gallery']);   
}

 // delete
public function delete($data){
    $this->db->where('id_gallery', $data['id_gallery']);   
    $this->db->delete('gallery', $data);   
}

}

In view: Folder Admin/Gallery edit.php

    <!-- Content Header (Page header) -->
<section class="content-header">
  <h1> Gallery </h1>
  <ol class="breadcrumb">
    <li><a href="#"><i class="fa fa-dashboard"> Dasbor</i></a></li>
      <li><a href="<?php echo base_url('backend/gallery')?>"><i class="fa fa-table"> </i>Gallery</a></li>
    <li class="active"> Edit</li>
  </ol>
</section>
<div class="box">
    <div class="box-header">
        <p>
            <a href="<?php echo base_url('backend/gallery/edit')?>" class="btn btn-success">
                <i class="fa fa-plus"></i>Edit</a>
        </p>
        <?php
            //Notifikasi
            if($this->session->flashdata('sukses')){
                echo '<div class="alert alert-success"><i class="fa fa-check">';
                echo $this->session->flashdata('sukses');
                echo '</div>';
            }?>
    </div>
    <div class="box-body">
        <?php
        //Notifikasi kalau ada input error
        echo validation_errors('<div class="alert alert-danger"><i class="fa fa-warning"></i>','</div>');
        //Open Form
        echo form_open(base_url('backend/gallery/edit'));
        ?>

        <div class="col-md-12">
            <div class="form-group">     
                <label>Gambar</label><input type="file" name="file" class="dropify" style="width: 100%; height: 200px;" required> <?php echo $gallery->file?>
            </div>
            <br>
            <div class="form-group">
                <label>tittle</label>
                <input type="text" name="tittle" class="form-control" placeholder="tittle" value="<?php echo $gallery->tittle?>" required>
            </div>
            <div class="form-group">
                <div class="box">
                    <div class="box-header">
                      <h3 class="box-title">Deskripsi</h3>
                    </div>
                            <textarea class="text" placeholder="Deskripsi" style="width:100%;height: 200px;line-height: 18px; border: 1px solid #dddddd; padding: 10px;" name="deskripsi"><?php echo $gallery->deskripsi?></textarea>
                    </div>
                  </div>
            </div>
            <div class="form-group">
                <input type="submit" name="submit" class="btn btn-success btn-lg" value="edit">
                <input type="reset" name="submit" class="btn btn-default btn-lg" value="Reset">
            </div>
        </div>

        <?php
        //Form Close
        echo form_close();
        ?>
    </div>
  • 写回答

1条回答 默认 最新

  • doushi1974 2018-10-04 16:29
    关注

    IN Gallery.php change this line

    public function edit($id_gallery){
       ...
           $this->Gallery_model->edit($data);
       ...
    }
    

    To

    public function edit($id_gallery){
       ...
           $this->Gallery_model->edit($id_gallery, $data);
       ...
    }
    

    This is because that method (in Gallery_model) is defined as this:

      public function edit($id_gallery, $data){ ... }
    

    Which requires both the gallery ID and the Data. You only sent it the data...

    Option 2

    Another option as it seems the ID is part of the Data would be to just remove that first argument in Gallery_model. So it looks like this:

    // Edit
    public function edit($data){
        $this->db->where('id_gallery', $data['id_gallery']);   
        $this->db->update('gallery', $data['id_gallery']);   //see below
    }
    

    The error is a bit confusing but it's probably coming from where this method is called in the "Gallery" controller.

    Last

    The last thing is this may be wrong:

    $this->db->update('gallery', $data['id_gallery']); 
    

    I don't use CI much, but it seems if you are doing an Update you would need more data then just the ID of the gallery. It's entirely possible this should be:

    $this->db->update('gallery', $data);
    

    But as I said I don't use CI much these days, so I can't say that for sure. But it seems like this would make much more sense:

         // Edit
    public function edit($id_gallery, $data){
        $this->db->where('id_gallery', $id_gallery);   
        $this->db->update('gallery', $data); 
    }
    
    //and call it this way $this->Gallery_model->edit($id_gallery, $data);
    

    Anyway, hope it helps

    Cheers!

    评论

报告相同问题?

悬赏问题

  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了