【发布时间】: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->m_students->get_edit($where);这里只有一个。
标签: php mysql codeigniter