0

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

この質問が少し当たり障りのない場合は申し訳ありません。

ありがとうピーター

4

2 に答える 2

1

それはすべて私のコードに帰着しました。モデルのクラス名は、モデルファイルの名前と同じである必要があります。

したがって、この場合、ファイルにlogin_model.phpという名前を付けてから、クラス自体にLogin_modelという名前を付ける必要があります(最初の文字は大文字、他のすべての文字は小文字にする必要があります)。コントローラでモデルを呼び出すときは、次のようにすべて小文字にする必要があります。

$this->load->model('login_model');

努力とコメントをありがとうございました:)これが将来の誰かの助けになることを願っています:)

于 2012-08-09T19:14:33.020 に答える
0

ファイルの名前を大文字にしてみますか?user_model.phpからUser_model.php?

于 2015-09-21T23:35:31.043 に答える