php - 类型: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);
}
}
}
}
解决方案
您没有为模型函数提供所需的参数,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
.
推荐阅读
- bots - 如何让我的 AIML 机器人只做出一个响应?
- python-3.x - 手动排序算法中的逻辑错误
- node.js - 创建一个窗口并在单击关闭按钮时将其隐藏
- performance - 基于 2 列和 1 行的条件查找和返回数据的最佳方法
- r - 使用列名和 ggplot2 创建一个函数
- python-3.x - Counter 的 most_common 方法的底层实现是什么?
- javascript - 如何使用 Bull 在 Node.js 中将我的函数作为后台进程执行?
- c - 选择在写入时阻止接收 ENOSPC
- typescript - 使用 Typescript 反应 useState 以设置嵌套类型对象
- excel - 存储在 SharePoint 库中的 Access DB 的并发和连接问题