【问题标题】:Codeigniter: An uncaught Exception was encountered Type: ArgumentCountErrorCodeigniter:遇到未捕获的异常类型:ArgumentCountError
【发布时间】:2020-04-22 11:49:35
【问题描述】:

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

消息:函数 Dashboard::contentedit() 的参数太少,在第 514 行的 /home/muanetor/matematika.muanetoraya.com/system/core/CodeIgniter.php 中传递了 0,而预期正好是 1

文件名:/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);
        }
    }

内容编辑.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>

【问题讨论】:

    标签: php codeigniter backend crud


    【解决方案1】:

    我猜,这个错误只有在你尝试访问控制器时才发生,而没有像

    这样的参数
    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();
        }
    }
    

    【讨论】:

    • 好的,谢谢,为你竖起大拇指,通过你的回答找到了解决方案,我尝试使用参数访问控制器,它解决了
    猜你喜欢
    • 2019-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多