我在登录时遇到问题我遇到了类似的错误“致命错误:在C:\ xampp \ htdocs \ cms \ application \ controllers \ admin \中调用未定义的方法User_m :: get_by() user.php在第10行“
这是我的user_m.php模态文件
<run-privileged>
这是我的查看文件login.php
class User_m extends CI_Model{
protected $_table_name = 'users';
protected $_order_by = 'name';
public $rules = array(
'email' => array(
'field' => 'email',
'label' => 'Email',
'rules' => 'trim|required|valid_email|xss_clean'
),
'password' => array(
'field' => 'password',
'label' => 'Password',
'rules' => 'trim|required'
)
);
public function __construct()
{
parent::__construct();
}
public function login()
{
$user = $this->get_by(array(
'email' => $this->input->post('email'),
'password' =>$this->hash($this->input->post('password'))
), TRUE);
if (count($user)) {
$data = array(
'name' => $user->name,
'email' => $user->email,
'id' => $user->id,
'loggedin' => TRUE,
);
$this->session->set_userdata($data);
}
}
public function logout()
{
$this->session->sess_destroy();
}
public function loggedin()
{
return (bool) $this->session->userdata('loggedin');
}
public function hash($string)
{
return hash('sha512', $string . config_item('encryption_key'));
}
}
这是我的控制器user.php
<div class="modal-header">
<h3>Log in</h3>
<p>Please log in using your credentials</p>
</div>
<div class="modal-body">
<?php echo validation_errors(); ?>
<?php echo form_open(); ?>
<table class="table">
<tr>
<td>Email</td>
<td><?php echo form_input('email'); ?></td>
</tr>
<tr>
<td>Password</td>
<td><?php echo form_password('password'); ?></td>
</tr>
<tr>
<td></td>
<td><?php echo form_submit('submit', 'Log in', 'class="btn btn-primary"'); ?></td>
</tr>
</table>
<?php echo form_close(); ?>
</div>
答案 0 :(得分:0)
您正在使用该模型,因此您应该将语法更改为以下内容:
$this->db->get('*')
->where('email', $email)->where('password', $password);
如果你想调用这个函数,你应该在模型类中定义它并将它添加到它自己的类中。
答案 1 :(得分:-1)
在user_m.php模式文件中更改此行:
class User_m extends CI_Model{
到
class User_m extends MY_Model