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

Codeigniter: An uncaught Exception was encountered Type: ArgumentCountError

尝试编辑内容时出现错误,当我按“更新内容”时出现错误 遇到未捕获的异常 类型:ArgumentCountError

消息:函数 Dashboard::contentedit() 的参数太少,在第 514 行 /home/muanetor/matematika.muanetoraya.com/system/core/CodeIgniter.php 中传递了 0 个参数 [=1] =12=]

文件名:/home/muanetor/matematika.muanetoraya.com/application/controllers/Dashboard.php

行号:145

回溯:

文件:/home/muanetor/matematika.muanetoraya.com/index.php 线路:315 函数:require_once

控制器:

function contentedit($id){
        if(isset($_POST['simpan'])){
            if ($_FILES['gambar']['error'] <> 4) {
                $nmfile = "file_".time();
                $config['upload_path']      = './upload/gambar';
                $config['allowed_types']    = 'jpg|png|gif|bmp';
                $config['file_name']        = $nmfile;

                $this->load->library('upload', $config);

                if (!$this->upload->do_upload('gambar')) {
                    $error = array('error' => $this->upload->display_errors());
                    $this->index($error);
                } else {
                    $hasil  = $this->upload->data();
                    $data = array(
                        'judul_content' => $this->input->post('judul',true),
                        'isi_content'   => $this->input->post('isi',true),
                        'kategori'      => $this->input->post('kategori',true),
                        'gambar'        => $hasil['file_name'],
                        'tanggal'       => date("Y-m-d h:i:s"));
                    $this->db->where('id',$this->input->post('id',true));
                    $this->db->update('content',$data);
                    redirect('dashboard/content/'.$this->input->post('kategori',true));
                }
            } else {
                    $data = array(
                        'judul_content' => $this->input->post('judul',true),
                        'isi_content'   => $this->input->post('isi',true),
                        'kategori'      => $this->input->post('kategori',true),
                        'tanggal'       => date("Y-m-d h:i:s"),
                    );
                $this->db->where('id',$this->input->post('id',true));
                $this->db->update('content',$data);
                redirect('dashboard/content/'.$this->input->post('kategori',true));
            }
        }else{
            $data['title'] = 'Modul Halaman';
            $data['record'] = $this->db->get_where('content',array('id'=>$id))->row_array();
            $this->template->load('admin/v_template','admin/v_content_edit',$data);
        }
    }

Contentedit.php

<div class="panel-body">
                                <?php $this->load->view('admin/editor') ?>
                                <?php echo form_open_multipart('dashboard/contentedit') ?>
                                    <div class="form-group">
                                        <label>Judul Content</label>
                                        <input style="width: 50%;" name="judul" type="text" class="form-control" value="<?php echo $record['judul_content'] ?>" required="">
                                        <input name="id" type="hidden" class="form-control" value="<?php echo $record['id'] ?>">
                                        <input name="kategori" type="hidden" class="form-control" value="<?php echo $record['kategori'] ?>">
                                    </div>
                                    <div class="form-group">
                                        <label>Isi Content</label>
                                        <textarea name="isi" class="form-control" rows="6"><?php echo $record['isi_content'] ?></textarea>
                                    </div>
                                    <div class="form-group">
                                        <label>Gambar</label>
                                        <input name="gambar" type="file">
                                        <p class="help-block">jpg | png | gif</p>
                                    </div>
                                    <button name="simpan" type="submit" class="btn btn-primary"><i class="glyphicon glyphicon-send"></i> Update Content</button> | <button type="reset" class="btn btn-danger">Reset</button>
                                </form>
                            </div>
                            <!-- /.panel-body -->
                        </div>
                    </div>
                </div>

我想,只有当您尝试访问不带参数的控制器时才会出现此错误,例如

http://matematika.muanetoraya.com/index.php/dashboard/contentedit

如果你像下面这样访问控制器,应该不会出错

http://matematika.muanetoraya.com/index.php/dashboard/contentedit/2

您可以通过将默认值设置为 $id

来解决此问题
public function contentedit($id = -1){
    if($id != -1){
         //put your code here
    }else{
        show_404();
    }
}