2012-02-27 72 views
0

我得到這個錯誤,我不知道爲什麼。致命錯誤:調用未定義的函數 - 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

+0

用'**'圍繞函數做些什麼?相當肯定會造成問題 – 2012-02-27 09:14:23

+0

它是加粗的功能,但不能在代碼視圖:) – 2012-02-27 09:15:17

+0

Mert,你仍然需要返回'$ activatecode'。 :-)爲什麼不使用'substr(md5(microtime()。'somesalt'),0,10)'? – TerryE 2012-02-27 10:23:41

回答

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)]; 
+0

+1 Good catch :) – Sarfraz 2012-02-27 09:19:34

+0

來自PHP手冊「** Note **:出於同樣的目的,也可以使用大括號來訪問字符串,例如$ str {42},但是,從PHP 5.3開始不推薦使用此語法.0。改爲使用方括號,例如$ str [42]。「 – TerryE 2012-02-27 09:35:13

+0

thanx TerryE,更新了答案。 – 2012-02-27 09:52:18

1

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

調用名稱爲$base = 'ABCDEFGHIJKLMNOPQRSTWXYZabcdefghıjklmnoprstwxyz123456789'的內容的函數,從而發生錯誤;

+0

順便說一句,索引操作符是''''不''()',你需要返回'$ activatecode'(帶'$')。 – TerryE 2012-02-27 09:25:51

相關問題