Symfony启用自定义包ClassNotFoundException

时间:2017-07-01 21:48:03

标签: php symfony

我想安装自己的捆绑包,所以我做了     作曲家需要" al37350 / fftt-bundle":" *"

然后我在AppKernel.php中激活了捆绑包

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "AlFFTTBundle" from namespace "Al\FFTTBundle".
Did you forget a "use" statement for another namespace? in /var/www/yoloFFTT/app/AppKernel.php:19
Stack trace:
#0 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(450): AppKernel->registerBundles()
#1 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php(116): Symfony\Component\HttpKernel\Kernel->initializeBundles()
#2 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(137): Symfony\Component\HttpKernel\Kernel->boot()
#3 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php(124): Symfony\Bundle\FrameworkBundle\Console\Application->registerCommands()
#4 /var/www/yoloFFTT/vendor/symfony/symfony/src/Symfony/Component/Console/Application.php(90): Symfony\Bundle\FrameworkBundle\Console\Application->add(Object(Symfony\Co in /var/www/yoloFFTT/app/AppKernel.php on line 19

但是当我做了一个php / bin控制台时,我有这个错误:

src
    Al
        FFTTBundle

bundle的文件结构:

final AIConfiguration config = new 
AIConfiguration("your key",
            AIConfiguration.SupportedLanguages.English,
            AIConfiguration.RecognitionEngine.System);
    AIRequest request = new AIRequest("your text request");
    AIService aiService = AIService.getService("implement new AIService", config);

    try {
        aiService.textRequest(request);
    } catch (AIServiceException e) {
        e.printStackTrace();
    }

,AlFFTTBundle.php的命名空间是Al \ FFTTBundle;

如果捆绑包不在供应商目录中,那么它有用吗?

2 个答案:

答案 0 :(得分:1)

你的bundle中的composer.json是否包含psr-0或psr-4自动加载?

示例:

"autoload": {
    "psr-4": {
        "Al\\FFTTBundle\\": "src/AlFFTTBundle",
    }
}

有关详细信息,请参阅:https://seld.be/notes/psr-4-autoloading-support-in-composer

答案 1 :(得分:0)

在composer.json中输入此条目后

function addToCart(product_id, obj){
        var qty = $(obj).closest('tr').find('#txtAcrescimo').val();
        console.log(qty);

        var $input = $("#txtAcrescimo");

        // Colocar a 0 ao início
        $input.val(1);
        if ($(this).hasClass('acrescimo'))
            $input.val(parseInt($input.val())+1);
        else if ($input.val()>=1)
            $input.val(parseInt($input.val())-1);

        console.log($("#txtAcrescimo").val());
 }

运行:"autoload": { "psr-4": { "Al\\FFTTBundle\\": "src/AlFFTTBundle", } }