php - 在 Codeigniter 上调用未定义的函数

标签 php codeigniter reset

我有重置用户密码的类(class)。但是代码总是给我一个错误:

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 可用以便它不是未定义的?

最佳答案

newRandomPwd() 不是一个全局函数而是一个对象方法,你应该使用$this

$newPwd = newRandomPwd(); 更改为 $newPwd = $this->newRandomPwd();

关于php - 在 Codeigniter 上调用未定义的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8966587/

相关文章:

php - 从数据库检索特定数据/值 1 行 PHP

php - 在 Codeigniter 中创建我自己的 base_url()

javascript - 使用ajax和codeigniter上传图像文件总是抛出upload_path错误

reset - 为什么不能重置 IFS 变量?

java.io.IOException : mark/reset not supported Java Audio Input Stream/Buffered Input Stream 异常

python - 在 Python 中保持字典中的值相同

php - 函数返回错误响应

php - SVN Apache 提交后更新 web 文件

php - CodeIgniter 探查器没有捕获插入

php - MVC 架构中的数据和表单验证