php - 类型 : ArgumentCountError Message: Too few arguments to function

标签 php mysql codeigniter

帮助我..我收到错误类型: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);
    }
}

我的 Controller

    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);
            }
        }
    }
}

最佳答案

您没有向模型函数 get_edit() 提供所需的参数,而仅提供 $where 一个参数。

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

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

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

您只能在 $data 之后调用带有 2 个参数的 get_edit($data, $u_id)

关于php - 类型 : ArgumentCountError Message: Too few arguments to function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59710826/

相关文章:

php选择查询字段列表中的未知列?

mysql - mySQL复合主键

php - Hangman php从数据库中生成新的随机单词

CodeIgniter 路由总是通过 index.php?

php - 我的mysqli插入查询无法正常工作

PHP MySQLi While 循环

codeigniter - 如何将模型加载到助手?

javascript - CSS 和 JS 未在 CodeIgniter 中加载

PHP/MySQL 帖子类别

php - 使用 httpd 将 www.domain.com 和 domain.com 重定向到 subdomain.domain.com