【发布时间】:2014-08-02 08:17:14
【问题描述】:
我正在使用 Symfony 2.4
我有一个 PHP 文件 OAuth.php,其中包含多个类。
OAuth.php 代码如下
<?php
namespace RT\AuthBundle\DependencyInjection\Vzaar;
use Exception;
class OAuthException extends Exception {
// pass
}
class OAuthConsumer {
//some code
}
class OAuthToken {
//some code
}
?>
我继承了 Vzaar.php 文件中的上述文件,该文件位于相同的命名空间中,其代码如下
<?php
namespace RT\AuthBundle\DependencyInjection\Vzaar;
/*require_once 'OAuth.php';
require_once 'HttpRequest.php';
require_once 'AccountType.php';
require_once 'User.php';
require_once 'VideoDetails.php';
require_once 'VideoList.php';
require_once 'UploadSignature.php';*/
use RT\AuthBundle\DependencyInjection\Vzaar\OAuth;
use RT\AuthBundle\DependencyInjection\Vzaar\HttpRequest;
use RT\AuthBundle\DependencyInjection\Vzaar\AccountType;
use RT\AuthBundle\DependencyInjection\Vzaar\User;
use RT\AuthBundle\DependencyInjection\Vzaar\VideoDetails;
use RT\AuthBundle\DependencyInjection\Vzaar\VideoList;
use RT\AuthBundle\DependencyInjection\Vzaar\UploadSignature;
//use RT\AuthBundle\DependencyInjection\Vzaar\OAuth\OAuthConsumer;
Class Profile
{
public static function setAuth($_url, $_method = 'GET')
{
$consumer = new OAuthConsumer('', '');
//some code
}
}
?>
创建 OAuthConsumer 类的新对象会引发错误
Fatal error: Class 'RT\AuthBundle\DependencyInjection\Vzaar\OAuthConsumer' not found in /var/temp/rt-web/src/RT/AuthBundle/DependencyInjection/Vzaar/Vzaar.php
1/1 ClassNotFoundException: Attempted to load class "OAuthConsumer" from namespace "RT\AuthBundle\DependencyInjection\Vzaar" in /var/temp/rt-web/src/RT/AuthBundle/DependencyInjection/Vzaar/Vzaar.php line 378. Do you need to "use" it from another namespace?
【问题讨论】:
-
为什么
OAuth.php中除了OAuth之外还有其他类? Symfony 正在OAuthConsumer.php中寻找OAuthConsumer -
@FuzzyTree 我知道这一点,但我想知道有什么办法可以实现吗??这是预定义的类,我还没有创建
-
require_once 'OAuth.php'不工作吗? -
来自PHP : namespaces.importing 的评论 语句不加载类文件。您必须使用 语句或使用自动加载函数来执行此操作。
-
@Log1cツ Symfony 将姓氏视为文件名。即
use RT\AuthBundle\ExternalClass\SimpleImage;那么文件夹ExternalClass内必须有SimpleImage.php文件,我想继承SimpleImage类中的类,在核心php中它正在工作,但没有symfony,我希望在 Symfony 中也有一些方法可以做同样的事情......
标签: php symfony classnotfoundexception fatal-error