wzhw666 发表于 2009-4-14 13:28:54

controller同一文件不同function的调用出错

class Verifycode extends Controller {

    function Verifycode()
    {
      parent::Controller();   
    }

    function index() {
      session_start();
      $verifyCode = getRandomCode();
      $_SESSION["verifyCode"] = $verifyCode;
      $imgWidth = $_REQUEST["width"];
      $imgHeight = $_REQUEST["height"];
      $imgFont = $_REQUEST["font"];
      
      if($imgWidth == "") $imgWidth = 80;
      if($imgHeight == "") $imgHeight = 20;
      if($imgFont == "") $imgFont = 6;
      doOutputImg($verifyCode, $imgWidth, $imgHeight, $imgFont);
    }
   
    //获取随机数字字符串
    function getRandomCode($length=4) {
      $glbVerifySeed = "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
      
      $bgnIdx = 0;
      $endIdx = strlen($glbVerifySeed)-1;
      
      $code = "";
      for($i=0; $i<$length; $i++) {
            $curPos = rand($bgnIdx, $endIdx);
            $code .= substr($glbVerifySeed, $curPos, 1);
      }
      
      return $code;
    }
   


报错为:
Fatal error:Call to undefined functiongetrandomcode() in D:\xampp\htdocs\webgame\system\application\controllers\verifycode.php on line 23

moorland 发表于 2009-4-14 15:38:07

应该这样调用:
$verifyCode = $this->getRandomCode();

Hex 发表于 2009-4-14 16:40:52

感叹某些朋友在用了框架以后,把 PHP 基础知识和面向对象的基础知识都忘了。。。。。
希望不要把框架看成是火星来客,他就是普通的 PHP 程序。

yuwen002 发表于 2009-4-15 08:49:50

{:3_53:}
呵呵,基础很重要

liwei 发表于 2009-4-15 10:27:48

是啊,要习惯CI的语法,不过我蛮喜欢这个格式的, ->->->->感觉很high

doutu 发表于 2009-4-18 17:38:05

像这样的问题自己不思考一下就贴来让大伙帮忙,作者应该反思一下。不然永远原地踏步
页: [1]
查看完整版本: controller同一文件不同function的调用出错