私は最初の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();の下にあるコードはすべてロードされています。表示されません。モデルもロードされています。関数を呼び出そうとするとすぐに、スクリプトが自殺します。
この質問が少し当たり障りのない場合は申し訳ありません。
ありがとうピーター