symfony2:找不到包含在 AppKernel 中的类 [英] symfony2: class included in AppKernel can not be found

查看:32
本文介绍了symfony2:找不到包含在 AppKernel 中的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个app/AppKernel:

getEnvironment(), array('dev', 'test'))) {#$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();$bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();$bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();}返回 $bundles;}公共函数 registerContainerConfiguration(LoaderInterface $loader){$loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');}

还有这个类src/Sports/FrontendBundle/SportsFrontendBundle.php:

命名空间 Sports\FrontendBundle;使用 Symfony\Component\HttpKernel\Bundle\Bundle;类 SportsFrontendBundle 扩展 Bundle{}

我收到此错误:

<块引用>

致命错误:类 'Sports\FrontendBundle\SportsFrontendBundle' 不是在/home/tirengarfio/programacion/sports/app/AppKernel.php 上找到第 25 行

这是我的app/autoload.php:

EOF;如果(PHP_SAPI === 'cli'){$message = strip_tags($message);}死($消息);}//国际如果(!function_exists('intl_get_error_code')){require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');$loader->add('Sports', __DIR__ .'/../src');}AnnotationRegistry::registerLoader(array($loader, 'loadClass'));返回 $loader;

和我的composer.json:

<代码>{"name": "symfony/框架标准版","description": "《Symfony 标准版》发行版",自动加载":{psr-0":{":src/"}},要求": {"php": ">=5.3.3","symfony/symfony": "2.1.1","doctrine/orm": "2.2.*","doctrine/doctrine-bundle": "dev-master","twig/extensions": "dev-master","symfony/assetic-bundle": "dev-master","symfony/swiftmailer-bundle": "dev-master","symfony/monolog-bundle": "dev-master","sensio/framework-extra-bundle": "*","sensio/distribution-bundle": "*","sensio/generator-bundle": "*","friendsofsymfony/user-bundle": "*","jms/security-extra-bundle": "1.1.*","jms/di-extra-bundle": "1.0.*","jms/i18n-routing-bundle": "1.0.*",奏鸣曲项目/出口商":开发大师",奏鸣曲项目/jquery-bundle":开发大师",奏鸣曲项目/块包":开发大师",奏鸣曲项目/缓存包":开发大师",奏鸣曲项目/管理包":开发大师",奏鸣曲项目/用户包":开发大师",奏鸣曲项目/doctrine-orm-admin-bundle":开发大师","stof/doctrine-extensions-bundle": "dev-master"},脚本":{安装后cmd":["Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap","Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache","Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"],后更新-cmd":["Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap","Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache","Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"]},配置":{"bin-dir": "bin"},最低稳定性":开发",额外的": {"symfony-app-dir": "app","symfony-web-dir": "web"}}

有什么想法吗?

SF 2.1.1

贾维

解决方案

为了将来参考,如果您检出代码并直接复制供应商文件夹而不运行 Composer,可能会发生类似的问题.

要排除自动加载问题,您只需在 symfony2 文件夹中运行 install(假设您有 composer.phar ):

php composer.phar 安装

这将从 composer.lock 文件安装项目依赖项(如果存在),或者回退到 composer.json.

I have this app/AppKernel:

<?php

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
            new Symfony\Bundle\SecurityBundle\SecurityBundle(),
            new Symfony\Bundle\TwigBundle\TwigBundle(),
            new Symfony\Bundle\MonologBundle\MonologBundle(),
            new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(),
            new Symfony\Bundle\AsseticBundle\AsseticBundle(),
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
            new JMS\AopBundle\JMSAopBundle(),
            new JMS\DiExtraBundle\JMSDiExtraBundle($this),
            new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
            new JMS\I18nRoutingBundle\JMSI18nRoutingBundle(),
            new FOS\UserBundle\FOSUserBundle(),
            new Sports\FrontendBundle\SportsFrontendBundle(),   // line 25             
            new Sports\UserBundle\SportsUserBundle(),
            new Sonata\DefaultBundle\SonataDefaultBundle(),
            new Sonata\DoctrineORMAdminBundle\SonataDoctrineORMAdminBundle(),
            new Sonata\AdminBundle\SonataAdminBundle(),
            new Sonata\BlockBundle\SonataBlockBundle(),
            new Sonata\CacheBundle\SonataCacheBundle(),
            new Knp\Bundle\MenuBundle\KnpMenuBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle()
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
#$bundles[] = new Acme\DemoBundle\AcmeDemoBundle();
            $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
            $bundles[] = new Sensio\Bundle\DistributionBundle\SensioDistributionBundle();
            $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle();
        }

        return $bundles;
    }

    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load(__DIR__.'/config/config_'.$this->getEnvironment().'.yml');
    }

And this class src/Sports/FrontendBundle/SportsFrontendBundle.php:

namespace Sports\FrontendBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class SportsFrontendBundle extends Bundle
{
}

And Im getting this error:

Fatal error: Class 'Sports\FrontendBundle\SportsFrontendBundle' not found in /home/tirengarfio/programacion/sports/app/AppKernel.php on line 25

This is my app/autoload.php:

<?php

use Doctrine\Common\Annotations\AnnotationRegistry;

if (!$loader = @include __DIR__.'/../vendor/autoload.php') {

    $message = <<< EOF
<p>You must set up the project dependencies by running the following commands:</p>
<pre>
    curl -s http://getcomposer.org/installer | php
    php composer.phar install
</pre>

EOF;

    if (PHP_SAPI === 'cli') {
        $message = strip_tags($message);
    }

    die($message);
}

// intl
if (!function_exists('intl_get_error_code')) {
    require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';

    $loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
    $loader->add('Sports',   __DIR__ . '/../src');
}

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));

return $loader;

and my composer.json:

{
    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.1.1",
        "doctrine/orm": "2.2.*",
        "doctrine/doctrine-bundle": "dev-master",
        "twig/extensions": "dev-master",
        "symfony/assetic-bundle": "dev-master",
        "symfony/swiftmailer-bundle": "dev-master",
        "symfony/monolog-bundle": "dev-master",
        "sensio/framework-extra-bundle": "*",
        "sensio/distribution-bundle": "*",
        "sensio/generator-bundle": "*",
        "friendsofsymfony/user-bundle": "*",
        "jms/security-extra-bundle": "1.1.*",
        "jms/di-extra-bundle": "1.0.*",
        "jms/i18n-routing-bundle" : "1.0.*",
        "sonata-project/exporter" : "dev-master",
        "sonata-project/jquery-bundle" : "dev-master",
        "sonata-project/block-bundle" : "dev-master",
        "sonata-project/cache-bundle" : "dev-master",
        "sonata-project/admin-bundle" : "dev-master",
        "sonata-project/user-bundle" : "dev-master",
        "sonata-project/doctrine-orm-admin-bundle" : "dev-master",
        "stof/doctrine-extensions-bundle": "dev-master"
    },
    "scripts": {
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "config": {
        "bin-dir": "bin"
    },
    "minimum-stability": "dev",
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web"
    }
}

Any idea?

sf 2.1.1

Javi

解决方案

For future references, similar issues can happen if you checkout your code and copy the vendor folder directly without running composer.

To rule autoload issues out, you can simply run install in your symfony2 folder ( assuming you have composer.phar there ):

php composer.phar install

This will install the project dependencies from the composer.lock file if present, or fall back on the composer.json.

这篇关于symfony2:找不到包含在 AppKernel 中的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆