2012-02-27 31 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

関数を囲む '**'とは何ですか?かなり問題であると確信しています –

+0

大胆な機能ですが、コードビューでは機能しません:) –

+0

Mert、 '$ activatecode'を返す必要があります。 :-)なぜ、substr(md5(microtime()。 'somesalt')、0、10) 'を使うのはなぜですか? – TerryE

答えて

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良いキャッチ:) – Sarfraz

+0

PHPマニュアルから "**注**:同じ目的のために、$ str {42}のように中文字を使用して文字列にアクセスすることもできますが、この構文はPHP 5.3以降で廃止予定です.0。$ str [42]のように角括弧を代わりに使用してください。 " – TerryE

+0

thanx TerryE、更新された回答。 –

1

ライン

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

は、その名前が$base = 'ABCDEFGHIJKLMNOPQRSTWXYZabcdefghıjklmnoprstwxyz123456789'の内容であるため、エラーを返します。

+0

ところで、インデックス演算子は '[]'ではなく '()'で、 '$ activatecode'(' $ 'で)を返す必要があります。 – TerryE

関連する問題