首页 > 解决方案 > 类型:ArgumentCountError 消息:函数的参数太少

问题描述

帮帮我.. 我收到错误类型:ArgumentCountError 消息:函数 M_students::get_edit() 的参数太少我想显示我的 mysql 表中的所有条目,但我一直收到错误消息。我是 Codeigniter 的新手,无法真正弄清楚如何解决这个问题。

我的模特

<?php defined('BASEPATH') OR exit('No direct script access allowed');

class M_students extends CI_Model {

    public function __construct()
    {
        parent::__construct();
    }

    private static $table = 'students';
    private static $pk = 's_id';


    public function get_edit($data, $s_id)
    {
        return $this->db->set($data)->where(self::$pk, $s_id)->update(self::$table);
    }
}

我的控制器

    public function edit_data()
    {
        $this->load->helper(['form', 'notification']);
        $s_id = $this->uri->segment(3);
        $where = "s_id = '$s_id'";
        $data['student'] = $this->m_students->get_edit($where);

        if ($this->validation()) {
            $u_id = $this->input->post('s_id', TRUE);

            $data = [
                's_npsn' => $this->input->post('s_npsn', TRUE),
                's_namasekolah' => $this->input->post('s_namasekolah', TRUE),
                'kota' => $this->input->post('kota', TRUE),
                'provinsi' => $this->input->post('provinsi', TRUE),
                'u_updated_at' => date('Y-m-d H:i:s'),
                'u_updated_by' => $this->session->userdata['s_id'],
                'u_is_active' => $this->input->post('u_is_active', TRUE)
            ];

            $this->m_students->edit($data, $u_id);
            $this->session->set_flashdata('alert', success('Data user berhasil diperbarui.'));
            $data['title'] = "Data ".self::$title;
            $data['content'] = "dashboard/student-form";
            redirect('student');

        } else {
            $data['title'] = "Edit ".self::$title;
            $data['action'] = site_url(uri_string());
            $data['content'] = 'dashboard/student-form';
            if (!$s_id) {
                redirect('student');
            } else {
                $this->load->view('dashboard/index', $data);
            }
        }
    }
}

标签: phpmysqlcodeigniter

解决方案


您没有为模型函数提供所需的参数,get_edit()而只提供了一个$where.

$data['student'] = $this->m_students->get_edit($where);

而在数组命名后$data调用一个模型函数,该模型函数命名为edit()根据问题中提供的代码不存在的 2 个参数。

$this->m_students->edit($data, $u_id);

您应该只get_edit($data, $u_id)$data.


推荐阅读