2012-01-23 16 views
5

Ho la classe per reimpostare una password utente. Ma il codice è sempre mi dà un errore:Chiamata alla funzione non definita su Codeigniter

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

Ecco il mio codice:

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

Come faccio a fare il metodo newRandomPwd disponibili quindi non è definito?

risposta

20

newRandomPwd() non è una funzione globale ma un metodo di oggetto, è necessario utilizzare $this.

Change $newPwd = newRandomPwd();-$newPwd = $this->newRandomPwd();

+0

Sono nuovo di MVC .. grazie per il vostro aiuto. Ora funziona! – softboxkid

+0

+1 Grazie per avermi ricordato di globale e oggetto – Anthony

Problemi correlati