Web

Ошибка построения модели и контроллера в моем проекте веб-сайта

Пожалуйста, помогите мне, я не могу получить доступ к своему коду, он всегда выдает ошибку:

Обнаружено необработанное исключение Тип: ArgumentCountError

Сообщение: слишком мало аргументов для функции Quotation_model :: addModels (), 1 параметр передан в C:\xampp\htdocs\sangil\application\controllers\Quotation.php в строке 126, а ожидается 2

Имя файла: C:\xampp\htdocs\sangil\application\models\Quotation_model.php

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

Обратная трассировка:

Файл: C:\xampp\htdocs\sangil\application\controllers\Quotation.php Строка: 126 Функция: addModels

Файл: C:\xampp\htdocs\sangil\index.php Строка: 315 Функция: require_once

 

Теперь код:

Контроллер: Quotation.php

public function addQuotation() {

    $this->form_validation->set_rules('date', 'Date', 'trim|required');

    $this->form_validation->set_rules('reference_no', 'Reference No', 'trim|required');

    if ($this->form_validation->run() == false) {

        $this->add();

    } else {

        $warehouse_id = $this->input->post('warehouse', true);

        $data = array(

            "date"                         =>  $this->input->post('date'),

            "reference_no"            =>  $this->input->post('reference_no'),

            "warehouse_id"           =>  $this->input->post('warehouse'),

            "customer_id"             =>  $this->input->post('customer'),

            "biller_id"                    =>  $this->input->post('biller'),

            "total"                         =>  $this->input->post('grand_total'),

            "discount_value"         =>  $this->input->post('total_discount'),

            "tax_value"                  =>  $this->input->post('total_tax'),

            "note"                          =>  $this->input->post('note'),

            "shipping_city_id"        =>  $this->input->post('city'),

            "shipping_state_id"      =>  $this->input->post('state'),

            "shipping_country_id"  =>  $this->input->post('country'),

            "shipping_address"      =>  $this->input->post('address'),

            "shipping_charge"       =>  $this->input->post('shipping_charge'),

            "internal_note"            =>  $this->input->post('internal_note'),

            "mode_of_transport"    =>  $this->input->post('mode_of_transport'),

            "transporter_name"      =>  $this->input->post('transporter_name'),

            "transporter_code"       =>  $this->input->post('transporter_code'),

            "vehicle_regn_no"        =>  $this->input->post('vehicle_regn_no'),

            "user"                          =>  $this->session->userdata('user_id')

        );

        if ($quotation_id = $this->quotation_model->addModel($data)) {

            $log_data = array(

                'user_id'      => $this->session->userdata('user_id'),

                'table_id'.    => $quotation_id,

                'message'    => 'Quotation Inserted'

            );

            $this->log_model->insert_log($log_data);

            $sales_item_data = $this->input->post('table_data', true);

            $js_data = json_decode($sales_item_data);

            foreach ($js_data as $key => $value) {

                if ($value == null) {

                } else {

                    $product_id = $value->product_id;

                    $quantity = $value->quantity;

                    $data = array(

                        "product_id" => $value->product_id,

                        "quantity" => $value->quantity,

                        "price" => $value->price,

                        "gross_total" => $value->total,

                        "discount_id" => $value->discount_id,

                        "discount_value" => $value->discount_value,

                        "discount" => $value->discount,

                        "tax_id" => $value->tax_id,

                        "tax_value" => $value->tax_value,

                        "tax" => $value->tax,

                        "quotation_id" => $quotation_id

                    );

                    //$this->sales_model>checkProductInWarehouse($product_id,$quantity,$warehouse_id);

                    if ($this->quotation_model->addQuotationItem($data, $product_id, $warehouse_id, $quantity)) {

                    } else {

                    }

                }

            }

            redirect('quotation/view/'.$quotation_id);

        } else {

            redirect('quotation', 'refresh');

        }

    }

}

 

Модель: Quotation_model.php

public function addModel($data, $invoice) {

    if ($this->db->insert('quotation', $data)) {

        return $this->db->insert_id();

    } else {

        return FALSE;

    }

}

 

Ответ 1

Вы создаете модель с 2 входными данными $data и $invoice

public function addModel ($data, $invoice)

но передается только 1 параметр на вход в контроллер, когда вы вызываете модель

$this->quote_model->addModel ($data)

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

 

Ответ 2

Можно поступить следующим образом:

public function addModel($data) {

    if ($this->db->insert('quotation', $data)) {

        return $this->db->insert_id();

    } 

    return false;

}

Схожие статьи

Информационная архитектура сайта: основы для начинающих разработчиков
Web

Информационная архитектура сайта: основы для начинающих разработчиков

Селениум: тестирование веб-приложений и другие полезные функции
Web

Селениум: тестирование веб-приложений и другие полезные функции

Как переопределить стиль в CSS: знакомство с CSS для новичков
Web

Как переопределить стиль в CSS: знакомство с CSS для новичков

Web

Как делать асинхронные HTTP-запросы в PHP

×