致命错误:调用未定义的函数 - codeigniter

时间:2012-02-27 09:10:23

标签: php codeigniter

我得到这个错误我不知道为什么。

我有一个产生随机字符的函数

function randomString($length) {
        $len = $length;
        $base = 'ABCDEFGHIJKLMNOPQRSTWXYZabcdefghıjklmnoprstwxyz123456789';
        $max = strlen($base) - 1;
        $activatecode = '';
        mt_srand((double) microtime() * 1000000);
        while (strlen($activatecode) < $len + 1)
            $activatecode.=$base(mt_rand(0, $max));

        return activatecode;
    }

我在

中调用此函数
public function kayitBasarili() {
        $this->load->view('kayitBasarili');

        $username = $this->input->post('username');
        $email = $this->input->post('email');
        $password = $this->input->post('password');

        $data = array();

        $data['username'] = $username;
        $data['email'] = $email;
        $data['password'] = $password;

        **$activationCode = $this->randomString(10);** 

        $this->load->view('kayitBasarili', $data);
        $this->kayitmodel->uyeEkle($username, $email, $password,$activationCode);
    }

为什么我收到此错误? enter image description here

2 个答案:

答案 0 :(得分:4)

看看这一行:

$activatecode.=$base(mt_rand(0, $max)); // Your calling the string as a function

它应该是:

$activatecode.=$base{mt_rand(0, $max)};

$activatecode.=$base[mt_rand(0, $max)];

答案 1 :(得分:1)

该行

$activatecode.=$base(mt_rand(0, $max));

调用名称为$base = 'ABCDEFGHIJKLMNOPQRSTWXYZabcdefghıjklmnoprstwxyz123456789'内容的函数,因此出错;