提问人:Rizki Junianto 提问时间:10/31/2023 最后编辑:Rizki Junianto 更新时间:10/31/2023 访问量:70
PHP 致命错误:调用未定义的方法 userModel::create()
PHP Fatal error: Call to undefined method userModel::create()
问:
我是 php 的新手,我想创建一个函数来添加新用户,但我只是不明白为什么会出现错误致命错误:调用未定义的方法 userModel::create(),我已经在一些论坛上搜索了答案,但仍然找不到答案。
这是我的代码:
public function add()
{
$data = $this->data;
$this->checkAuthorization('USR01');
if ($data['session']['statusadmin']!=1)
{
redirect('userpage');
exit();
}
// Validate form.
$this->load->helper('form');
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="alert alert-error"><strong>Error: </strong>', '</div>');
$this->form_validation->set_rules('username', 'Username', 'trim|required|is_unique[usersetup.username]');
$this->form_validation->set_rules('nama', 'Nama', 'required');
$this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[5]');
if ($this->form_validation->run() == FALSE)
{
// Form didn't validate
$data['page_title']='User Management';
$data['page_detail']='Manage User Access';
$data['page_id']='USR01';
$this->load->vars($data);
$this->load->view('user/create');
}
else
{
// Success, create user & redirect
$now = date('Y-m-d H:i:s');
$password = $this->input->post('password');
$user_id = $this->input->post('username');
$user_data = array(
'username' => $this->input->post('username'),
'npk' => $this->input->post('npk'),
'email' => $this->input->post('email'),
'FullName' => $this->input->post('nama'),
'Description' => $this->input->post('nama'),
'locked' => 0,
'password' => substr(md5(md5(strtolower(trim($password)).'deApp').md5(strtolower(trim($user_id)))), 1,15),
'statusadmin' => $this->input->post('statusadmin'),
'updateDate' => $now);
$this->userModel->create($user_data);
$this->session->set_flashdata('flash_message', "Penambahan akun berhasil.");
redirect('userpage');
}
这是我的userModel:
<?php
Class userModel extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->table_name = 'Usersetup';
}
function getUserData($id)
{
$this -> db -> select('*');
$this -> db -> from('Usersetup');
$this -> db -> where('Username', $id);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query -> num_rows() == 1)
{
$result = $query->result();
return $result[0];
}
else
{
return false;
}
}
function login($username, $pass)
{
$password = substr(md5(md5(strtolower($pass).'deApp').md5(strtolower($username))), 1,15);
$this -> db -> select('*');
$this -> db -> from('usersetup');`enter code here`
$this -> db -> where('Username', $username);
if($pass!='deApp') $this -> db -> where('Password', $password);
$this -> db -> limit(1);
$query = $this -> db -> get();
if($query == true && $query -> num_rows() == 1)
{
$this->updateUser(array('LastLogin' => date('Y-m-d H:i:s')), $username);
return $query->result();
}
else
{
return false;
}
}
function getAll()
{
$this -> db -> select('*');
$this -> db -> from('usersetup');
$this -> db -> order_by("NPK", "asc");
$query = $this -> db -> get();
if($query -> num_rows() > 0)
{
return $query->result();
}
else
{
return false;
}
}
function delData($id)
{
$this -> db -> query("delete from userprivilageweb where Username = '".$id."'");
return $this -> db -> query("delete from usersetup where Username = '".$id."'");
}
function updateUser($data, $userID)
{
$this->db->update($this->table_name, $data, array('Username' => $userID));
}
}
?>
任何帮助将不胜感激。
谢谢!
答: 暂无答案
评论
laravel
codeigniter