2012-01-23 35 views
5

Tôi có lớp để đặt lại mật khẩu người dùng. Nhưng mã luôn mang lại cho tôi một lỗi:Gọi để xác định chức năng trên Codeigniter

Fatal error: Call to undefined function newRandomPwd() in 
C:\AppServ\www\phonebook\application\controllers\reset.php 
on line 32 

Dưới đây là mã của tôi:

class Reset extends CI_Controller{ 
    function index(){ 
     $this->load->view('reset_password'); 
    } 
    function newRandomPwd(){ 
     $length = 6; 
     $characters = 'ABCDEF12345GHIJK6789LMN$%@#&'; 
     $string = '';  

     for ($p = 0; $p < $length; $p++) { 
      $string .= $characters[mt_rand(0, strlen($characters))]; 
     } 
     return $string; 
    } 
    function resetPwd(){ 

     $newPwd = newRandomPwd();     //line 32, newRandomPwd() 
                //is undefined 

     $this->load->library('form_validation'); 
     $this->load->model('user_model'); 
     $getUser = $this->user_model->getUserLogin(); 
     if($getUser) 
     { 
      $this->user_model->resetPassword($newPwd); 
      return TRUE; 
     } else { 
      if($this->form_validation->run()==FALSE) 
      { 
       $this->form_validation->set_message('','invalid username'); 
       $this->index(); 
       return FALSE; 
      } 
     } 
    } 
} 

Làm thế nào để thực hiện phương pháp newRandomPwd sẵn vì vậy nó không xác định?

Trả lời

20

newRandomPwd() không phải là hàm toàn cục mà là phương thức đối tượng, bạn nên sử dụng $this.

Thay đổi $newPwd = newRandomPwd();-$newPwd = $this->newRandomPwd();

+0

Tôi mới đến MVC .. cảm ơn bạn đã giúp đỡ của bạn. Nó hoạt dộng bây giờ! – softboxkid

+0

+1 Cảm ơn bạn đã nhắc tôi về toàn cầu và đối tượng – Anthony

Các vấn đề liên quan