我正在创建一个带有命名空间类的Yii项目。我的所有类都存储在projectRoot / protected / src / myNamespace中
在这个目录中,我在MyNamespace/Amazon/Amazon.php
控制器看起来像这样
use MyNamespace\Amazon\Amazon;
...
function actionIndex() {
echo Amazon::getBucketFromKey('key');
}
没关系,自动加载工作完美,这个类已加载。
Amazon.php看起来像这样:
class AmazonServer {
public static function getBucketFromKey($key) {
$criteria = new CDbCriteria;
$criteria->select = 'bucket';
$criteria->condition = 'userkey = :userkey AND enabled=:enabled';
$criteria->params = array(':userkey' => $key, ':enabled' => 1);
$bucket = Amazonuser::model()->find($criteria);
if ($bucket === null) {
throw new BucketNotFoundException('Bucket not found for this key.');
} else {
return $bucket->attributes['bucket'];
}
}
....
当我运行此脚本时,Yii返回错误
include(/var/www/yii3/vl/protected/config/../src/MyNamespace/Amazon/CDbCriteria.php): failed to open stream: No such file or directory
问题符合 $ criteria = new CDbCriteria;
为什么会这样?如何正确地从全局命名空间调用CDbCriteria和其他类?
调用new \ CDbCriteria没有帮助...