gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 15:15:39 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com