Codeigniter - 缺少参数1

时间:2017-07-10 20:12:14

标签: php codeigniter

我的大学任务有问题。我正在学习通过codeigniter创建更新功能,然后我收到了一个错误:

缺少Account :: update()

的参数1

当我按"提交"按钮。

控制器:

class Account extends CI_Controller {

public function __construct() {
    parent::__construct();

    $this->load->model('cpanel/account/account_model');
}

public function update($nim) {
    $this->form_validation->set_rules('nim', 'nim', 'required');
    $this->form_validation->set_rules('nama', 'nama', 'required');
    $this->form_validation->set_rules('sandi', 'sandi', 'required');
    $this->form_validation->set_rules('email', 'email', 'required');
    $this->form_validation->set_rules('telp', 'telp', 'required');

    if ($this->form_validation->run() === FALSE) {
        $data['akun'] = $this->account_model->detail();
        $data['detail'] = $this->account_model->detail($nim);
        $data = array('title'=> 'Mengubah Data Akun : '.$data['detail']['ortu_nama'], 'akun'=> $this->account_model->detail(), 'detail'=> $this->account_model->detail($nim), 'isi'=>'cpanel/account/account_edit_view');

        $this->load->view('cpanel/layout/wrapper',$data);
    } else {
        $data = array(
            'ortu_nim_mhs' => $this->input->post('nim'),
            'ortu_nama' => $this->input->post('nama'),
            'ortu_email' => $this->input->post('email'),
            'ortu_telp' => $this->input->post('telp')
            );

        $this->account_model->update($data);
        $konten = array('title'=>'Perubahan Data Sukses', 'isi'=>'cpanel/account/success_view');
        $this->load->view('cpanel/layout/wrapper', $konten);
    }
}}

型号:

class Account_model extends CI_Model {

public function __construct() {
    $this->load->database();
}

public function update($data) {
    $this->db->where('ortu_nim_mhs', $data['ortu_nim_mhs']);
    return $this->db->update('user_ortu', $data);
}

public function detail($nim = FALSE) {
    if ($nim === FALSE) {
        $query = $this->db->get('user_ortu');
        return $query->result_array();
    }
    $query = $this->db->get_where('user_ortu', array('ortu_nim_mhs'=>$nim));
    return $query->row_array();
}}

2 个答案:

答案 0 :(得分:0)

在模型功能中尝试$data = array();

public function update($data = array()) {
   $this->db->where('ortu_nim_mhs', $data['ortu_nim_mhs']);
   return $this->db->update('user_ortu', $data);
}

答案 1 :(得分:0)

在上面的代码中,如果您使用POST方法提交表单,则不需要函数参数。请查看以下内容。

public function update() {
    // Your code
}

但是,如果您使用get方法提交表单,则需要先设置验证数据,如下所示。

public function update() {
    $this->form_validation->set_data($this->input->get());
    $this->form_validation->set_rules('nim', 'nim', 'required');
    $this->form_validation->set_rules('nama', 'nama', 'required');
    $this->form_validation->set_rules('sandi', 'sandi', 'required');
    $this->form_validation->set_rules('email', 'email', 'required');
    $this->form_validation->set_rules('telp', 'telp', 'required');

    // Your other code
}

这会对你有所帮助。如果它不起作用,请告诉我。