提问人:softboxkid 提问时间:1/23/2012 最后编辑:Eric Leschinskisoftboxkid 更新时间:4/16/2014 访问量:35290
调用 Codeigniter 上的未定义函数
Call to undefined function on 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
答:
25赞
xdazz
1/23/2012
#1
newRandomPwd()
不是一个全局函数,而是一个对象方法,你应该使用 .$this
更改为$newPwd = newRandomPwd();
$newPwd = $this->newRandomPwd();
评论