jinchishuxue 2011-05-10 09:23:45 4197次浏览 2条回复 0 0 0

hi all, 我在component/下面添加了一个文件component/utils/Utils.php, Utils类里面有一个静态方法newPasswd().然后我在SiteController中调用 Utils::newPasswd(),会产生如下error:

PHP Error

include(Utils.php): failed to open stream: No such file or directory

/Library/WebServer/Documents/faceon/faceon_server/yii/framework/YiiBase.php(396)

384      /*@return boolean whether the class has been loaded successfully
385      */
386     public static function autoload($className)
387     {
388         // use include so that the error PHP file may appear
389         if(isset(self::$_coreClasses[$className]))
390             include(YII_PATH.self::$_coreClasses[$className]);
391         else if(isset(self::$classMap[$className]))
392             include(self::$classMap[$className]);
393         else
394         {
395             if(strpos($className,'\\')===false)
396               [b]  include($className.'.php');[/b]
397             else  // class name with namespace in PHP 5.3
398             {
399                 $namespace=str_replace('\\','.',ltrim($className,'\\'));
400                 if(($path=self::getPathOfAlias($namespace))!==false)
401                     include($path.'.php');
402                 else
403                     return false;
404             }
405             return class_exists($className,false) || interface_exists($className,false);
406         }
407         return true;
408     }

可能是很新手的问题,,在线等你的答复. thx

  • 回复于 2011-05-10 10:49 举报

    自问自答:
    原因很简单,我添加了新的文件utils.php后,需要在项目的config文件main.php中import该文件.

  • 回复于 2011-05-11 08:50 举报

    because YII的import方式类似JAVA
    不会引用子目录的

您需要登录后才可以回复。登录 | 立即注册