【问题标题】:Type: ArgumentCountError Message: Too few arguments to function类型:ArgumentCountError 消息:函数的参数太少
【发布时间】:2020-01-13 05:06:23
【问题描述】:

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

【问题讨论】:

  • 你需要传递两个参数你的函数$data['student'] = $this-&gt;m_students-&gt;get_edit($where);这里只有一个。

标签: php mysql codeigniter


【解决方案1】:

您没有为模型函数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)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-04
    • 1970-01-01
    • 2019-06-01
    • 2022-08-17
    • 2018-10-11
    • 2018-02-08
    相关资源
    最近更新 更多