5
我有一個用於重置用戶密碼的類。但是代碼總是給我一個錯誤:致電Codeigniter上的未定義函數
Fatal error: Call to undefined function newRandomPwd() in
C:\AppServ\www\phonebook\application\controllers\reset.php
on line 32
這裏是我的代碼:
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;
}
}
}
}
怎樣使newRandomPwd
可用,所以它不是不確定的方法是什麼?
我是新來的MVC ..謝謝你的幫助。它現在有效! – softboxkid
+1謝謝你提醒我關於全局和對象 – Anthony