php - ArgumentCountError-参数太少

标签 php codeigniter error-handling

我只是在学习codeigniter,并且有一个页面可以更新我的数据库。但我收到这样的错误:

Type: ArgumentCountError

Message: Too few arguments to function Inhouse::ubah(), 0 passed in D:\xampp\htdocs\slc\system\core\CodeIgniter.php on line 532 and exactly 1 expected

Filename: D:\xampp\htdocs\slc\application\controllers\Inhouse.php

Line Number: 120



我该如何解决这个问题?这是我的代码:

Controller :
public function ubah($id)
    {
        $data['title'] = 'Change Form - Data IHT Program';
        $data['inhouse'] = $this->Inhouse_model->getInhouseById($id);
        $data['user'] = $this->db->get_where('user', ['email' => $this->session->userdata('email')])->row_array();

        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('subtitle', 'Subtitle', 'required');
        $this->form_validation->set_rules('overview', 'Overview', 'required');
        $this->form_validation->set_rules('goals', 'Goals', 'required');
        $this->form_validation->set_rules('agenda1', 'Agenda 01', 'required');
        $this->form_validation->set_rules('agenda2', 'Agenda 02', 'required');
        $this->form_validation->set_rules('agenda3', 'Agenda 03', 'required');
        $this->form_validation->set_rules('agenda4', 'Agenda 04', 'required');
        $this->form_validation->set_rules('agenda5', 'Agenda 05', 'required');
        $this->form_validation->set_rules('agenda6', 'Agenda 06', 'required');
        $this->form_validation->set_rules('agenda7', 'Agenda 07', 'required');
        $this->form_validation->set_rules('agenda8', 'Agenda 08', 'required');
        $this->form_validation->set_rules('trainer', 'Trainer', 'required');

        if ($this->form_validation->run() == FALSE) {
            if (!$this->session->userdata('email')) {
                $this->load->view('templates/header', $data);
            } else {
                $this->load->view('templates/login_header', $data);
            }
            $this->load->view('inhouse/ubah', $data);
            $this->load->view('templates/footer');
        } else {
            // cek jika ada gampar yg diupload
            $upload_image = $_FILES['image']['name'];

            if ($upload_image) {
                $config['allowed_types'] = 'gif|jpg|png';
                $config['max_size'] = '5048';
                $config['upload_path'] = './assets/img/inhouse/';

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

                if ($this->upload->do_upload('image')) {
                    $old_image = $data['inhouse']['image'];
                    if ($old_image != 'default.jpg') {
                        unlink(FCPATH . 'assets/img/inhouse/' . $old_image);
                    } else {
                        $new_image = $this->upload->data('file_name');
                        $this->db->set('image', $new_image);
                    }
                } else {
                    echo $this->upload->display_errors();
                }
            }

            $this->db->set('image', $new_image);
            $this->db->where('id', $id);
            $this->db->update('inhouse', $data);

            $this->Inhouse_model->ubahInhouseProgram();
            $this->session->set_flashdata('flash', 'Diubah!');
            redirect('admin/product');
        }
    }

型号:
public function ubahInhouseProgram()
    {
        $data = [
            "image" => $this->input->post('image', true),
            "title" => $this->input->post('title', true),
            "subtitle" => $this->input->post('subtitle', true),
            "overview" => $this->input->post('overview', true),
            "goals" => $this->input->post('goals', true),
            "agenda1" => $this->input->post('agenda1', true),
            "agenda2" => $this->input->post('agenda2', true),
            "agenda3" => $this->input->post('agenda3', true),
            "agenda4" => $this->input->post('agenda4', true),
            "agenda5" => $this->input->post('agenda5', true),
            "agenda6" => $this->input->post('agenda6', true),
            "agenda7" => $this->input->post('agenda7', true),
            "agenda8" => $this->input->post('agenda8', true),
            "trainer" => $this->input->post('trainer', true)
        ];
        $this->db->where('id', $this->input->post('id'));
        $this->db->update('inhouse', $data);
    }

查看:
<div class="container">

    <div class="row mt-5 mb-5">
        <div class="col-lg-12">

            <!-- FORM -->
            <div class="card myshadow">
                <div class="card-header font-weight-bold">
                    <h2>Change Form Data IHT Program</h2>
                </div>
                <div class="card-body">


                    <?= form_open_multipart('inhouse/ubah'); ?>

                    <input type="hidden" name="id" value="<?= $inhouse['id']; ?>">


                    <div class="form-group mt-4">
                        <div class="">Picture</div>
                        <div class="row">
                            <div class="col-sm-4">
                                <img src="<?= base_url('assets/img/inhouse/') . $inhouse['image']; ?>" class="img-thumbnail">
                            </div>
                            <div class="col-sm-8">
                                <div class="custom-file">
                                    <input type="file" class="custom-file-input" id="image" name="image">
                                    <label class="custom-file-label" for="image">Choose file</label>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group mt-4">
                        <label for="title">Title</label>
                        <input type="text" name="title" class="form-control" id="title" value="<?= $inhouse['title'] ?>">
                        <small class="form-text text-danger"><?= form_error('title') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="subtitle">Subtitle</label>
                        <textarea type="text" name="subtitle" class="form-control" id="subtitle" rows="3"><?= $inhouse['subtitle']; ?></textarea>
                        <small class="form-text text-danger"><?= form_error('subtitle') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="overview">Overview</label>
                        <textarea type="text" name="overview" class="form-control" id="overview" rows="8"><?= $inhouse['overview'] ?></textarea>
                        <small class="form-text text-danger"><?= form_error('overview') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="goals">Goals</label>
                        <textarea type="text" name="goals" class="form-control" id="goals" rows="3"><?= $inhouse['goals'] ?></textarea>
                        <small class="form-text text-danger"><?= form_error('goals') ?></small>
                    </div>

                    <hr class="mt-5">

                    <div class="form-group mt-4">
                        <label for="agenda1">Agenda 01</label>
                        <input type="text" name="agenda1" class="form-control" id="agenda1" value="<?= $inhouse['agenda1'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda1') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="agenda2">Agenda 02</label>
                        <input type="text" name="agenda2" class="form-control" id="agenda2" value="<?= $inhouse['agenda2'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda2') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="agenda3">Agenda 03</label>
                        <input type="text" name="agenda3" class="form-control" id="agenda3" value="<?= $inhouse['agenda3'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda3') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="agenda4">Agenda 04</label>
                        <input type="text" name="agenda4" class="form-control" id="agenda4" value="<?= $inhouse['agenda4'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda4') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="agenda5">Agenda 05</label>
                        <input type="text" name="agenda5" class="form-control" id="agenda5" value="<?= $inhouse['agenda5'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda5') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="agenda6">Agenda 06</label>
                        <input type="text" name="agenda6" class="form-control" id="agenda6" value="<?= $inhouse['agenda6'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda6') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="agenda7">Agenda 07</label>
                        <input type="text" name="agenda7" class="form-control" id="agenda7" value="<?= $inhouse['agenda7'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda7') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="agenda8">Agenda 08</label>
                        <input type="text" name="agenda8" class="form-control" id="agenda8" value="<?= $inhouse['agenda8'] ?>">
                        <small class="form-text text-danger"><?= form_error('agenda8') ?></small>
                    </div>

                    <div class="form-group mt-4">
                        <label for="trainer">Trainer</label>
                        <input type="text" name="trainer" class="form-control" id="trainer" value="<?= $inhouse['trainer'] ?>">
                        <small class="form-text text-danger"><?= form_error('trainer') ?></small>
                    </div>
                    <button type="submit" name="ubah" class="btn btn-primary mt-5">Change Data</button>
                    </form>
                </div>
            </div>
            <!-- END FORM -->

        </div>
    </div>

</div>

最佳答案

像这样获取参数“$ this-> uri-> segment(2)”

exp:-htts://localhost/ci/50/60

$ this-> uri-> segment(2)//O/P 50

$ this-> uri-> segment(3)//O/P 60

欲了解更多信息,请点击这里Segments

public function ubah(){
 $this->uri->segment(2);
}

关于php - ArgumentCountError-参数太少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61349631/

相关文章:

php - Symfony 3.0 嵌套实体不保存

php - Elasticsearch和Symfony搜索单词的一部分

php - 连接两个 MySQL 列并输出 colB.name,其中 colA.id 等于 colB.id

php - Codeigniter 在查询中转义句点

php - 执行长 Action

php - Foreach 哎呀! `SELECT` 感到困惑

php - Codeigniter 根据选择的下拉列表 id 显示数据描述

Angular 可观察到的错误不会使用 ChangeDetectionStrategy.OnPush 刷新界面

sql-server - 我可以在事务期间在单独的事务中运行一些SQL吗

php - 如何获取错误代码的文本?