ArgumentCountError - слишком мало аргументов - PullRequest
0 голосов
/ 21 апреля 2020

Я только изучаю codeigniter, и у меня есть страница для обновления моей базы данных. но я получаю сообщение об ошибке:

Тип: ArgumentCountError

Сообщение: слишком мало аргументов для функции Inhouse :: ubah (), 0 передано в D: \ xampp \ htdocs \ slc \ system \ core \ CodeIgniter. php в строке 532 и ожидается ровно 1

Имя файла: D: \ xampp \ htdocs \ slc \ application \ controllers \ Inhouse. php

Номер строки: 120

Как я могу решить эту проблему? Это мой код:


Контроллер:

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>

Ответы [ 3 ]

0 голосов
/ 22 апреля 2020

Полагаю, эта ошибка возникает только при попытке доступа к контроллеру без аргументов, подобных

http://localhost/slc/index.php/ubah

Если вы обращаетесь к контроллеру, как показано ниже, не должно быть ошибки

http://localhost/slc/index.php/ubah/2

Вы можете исправить это, установив значение по умолчанию $id

public function ubah($id = -1){
    if($id != -1){
         //put your code here
    }else{
        show_404();
    }
}
0 голосов
/ 22 апреля 2020

Спасибо за все ваши ответы, я очень ценю вас, ребята, за то, что вы помогли мне исправить мой код ... но я просто удаляю "action" из моей form_opener_multipart ();

Из этого:

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

В это:

<?= form_open_multipart(); ?>

Я не очень понимаю, почему это может быть так, но теперь моя программа может быть запущена, вы, ребята, можете мне объяснить? я буду очень признателен за это.

И есть еще одна проблема, другой столбец моей таблицы базы данных может быть обновлен, кроме столбца "изображение".

0 голосов
/ 21 апреля 2020

Получите Аргумент как этот "$ this-> uri-> сегмент (2)"

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

$ this-> uri-> сегмент (2) // O / P 50

$ this-> uri-> сегмент (3) // O / P 60

для получения дополнительной информации go здесь сегментов

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