2012-08-09 4 views
0

제 첫 CodeIgniter 스크립트를 작성 중이며 누군가 다음 스크립트를로드 할 수 없습니다. 그러나 $ 결과 = $ 결과 아래에 간다 코드를로드CodeIgniter 모델이 올바르게로드되지 않습니다.

<?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; 
    } 
} 
?> 

내가 프로세스 기능을 확인할 수 있습니다 내 모델

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'); 
}  
} 

그리고 여기에 있습니다 : 여기

내 컨트롤러 파일입니다 = $ this-> users-> validate(); 나타나지 않습니다. 모델도로드 중입니다. 함수 호출을 시도하자마자 스크립트가 자체를 종료합니다.

죄송합니다.이 질문에 약간의 혼란이 있으시면 죄송합니다.

감사 피터

+0

아마 모델에서 사용하고있는 보안 라이브러리의 bcs가 발생하지만로드 할 코드가 없습니다. – tijs

+0

이 코드를 사용하여 모델을로드합니다. $ this-> load-> model ('users/login', 'users'); 컨트롤러 섹션의 상단에 게시됩니다. 모델이로드 중일 것 같습니다. 스크립트는 $ result = $ this-> users-> validate();에 도달하면 스크립트 자체가 종료됩니다. –

+0

'$ this-> input-> post ('some_data', TRUE);'// 두 번째 선택 매개 변수를 사용하면 XSS 필터를 통해 데이터를 실행할 수 있습니다. 두 번째 매개 변수를 부울 TRUE로 설정하면 활성화됩니다. – TigerTiger

답변

1

그것은 모두 내 코드에 내려왔다. 모델 클래스 이름은 모델 파일의 이름과 동일해야합니다.

그래서이 파일의 이름은 login_model.php이어야하고 클래스 자체는 Login_model이라고해야합니다 (첫 번째 문자는 대문자 여야하며 다른 모든 문자는 소문자 여야 함). 컨트롤러에서 모델을 호출 할 때 그것은 모든해야 소문자 같은 :

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

희망이 미래에 누군가에게 도움이됩니다, 당신은을 활용하려고 노력 및 의견 :

+2

추가 된 주석으로 클래스 이름은 어떤 종류의 대문자/소문자 혼합이 될 수 있지만 CodeIgniter는 다음과 같은 객체 변수를 반환합니다. 예를 들어, 클래스가 LoginModel이라면, 당신은'$ this-> loginmodel'으로 호출해야합니다. 이것은 라이브러리를 로딩하는 것입니다. –

+0

업데이트 주셔서 감사합니다 :) –

0

에 대한 모든 덕분에 파일 이름? user_model.php to User_model.php?

관련 문제