【发布时间】:2012-08-09 16:35:53
【问题描述】:
我正在编写我的第一个 CodeIgniter 脚本,但我无法加载以下模型,如果有人可以帮助我吗?
这是我的控制器文件:
public function process(){
// Load the model
$this->load->model('users/login', 'users');
// Validate the user can login
$result = $this->users->validate();
// Now we verify the result
if(!$result){
// If user did not validate, then show them login page again
$this->index();
}else{
// If user did validate,
// Send them to members area
redirect('home');
}
}
这是我的模型
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login_Model extends CI_Model{
function __construct()
{
// Call the Model constructor
parent::__construct();
}
public function validate(){
// grab user input
$username = $this->security->xss_clean($this->input->post('username'));
$password = $this->security->xss_clean($this->input->post('password'));
// Prep the query
$this->db->where('username', $username);
$this->db->where('password', $password);
// Run the query
$query = $this->db->get('users');
// Let's check if there are any results
if($query->num_rows == 1)
{
// If there is a user, then create session data
$row = $query->row();
$data = array(
'userid' => $row->userid,
'fname' => $row->fname,
'lname' => $row->lname,
'username' => $row->username,
'validated' => true
);
$this->session->set_userdata($data);
return true;
}
// If the previous process did not validate
// then return false.
return false;
}
}
?>
我可以确认进程函数正在加载,但是 $results = $result = $this->users->validate(); 下的任何代码没有出现。模型也在加载中,一旦我尝试调用一个函数,脚本就会自行终止。
对不起,如果这个问题有点乏味。
谢谢 彼得
【问题讨论】:
-
可能问题出在您在模型中使用的安全库的 bcs 中,但没有代码可以加载它。
-
我正在使用此代码加载模型 $this->load->model('users/login', 'users');它张贴在控制器部分的上方。模型似乎正在加载,脚本在到达 $result = $this->users->validate();
-
你可以使用
$this->input->post('some_data', TRUE);//第二个可选参数让你通过XSS过滤器运行数据。通过将第二个参数设置为布尔值 TRUE 来启用它; -
谢谢,我在那儿试过了,但什么也没做。我什至创建了一个公共函数 test() ,它说 echo 'test';并试图加载,但仍然没有运气:(
-
“脚本杀死自己” .... 任何错误消息?
标签: php codeigniter function model controller