Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to undefined function on Codeigniter

I have the class for resetting a user password. But the code is always gives me an error:

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

Here is my code:

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

How do I make the method newRandomPwd available so it's not undefined?

like image 465
softboxkid Avatar asked Jan 23 '12 02:01

softboxkid


1 Answers

newRandomPwd() is not a global function but a object method, you should use $this.

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

like image 53
xdazz Avatar answered Oct 03 '22 15:10

xdazz