4

我有这个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');
    }

而这堂课src/Sports/FrontendBundle/SportsFrontendBundle.php

namespace Sports\FrontendBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class SportsFrontendBundle extends Bundle
{
}

我得到这个错误:

致命错误:在第 25 行的 /home/tirengarfio/programacion/sports/app/AppKernel.php 中找不到类“Sports\FrontendBundle\SportsFrontendBundle”

这是我的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;

我的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"
    }
}

任何想法?

科幻小说 2.1.1

哈维

4

3 回答 3

7

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

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

php composer.phar install

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

于 2014-04-24T16:23:33.483 回答
5

这只是一个权限问题。我的捆绑文件夹不知何故获得了错误的权限。我将它们设置为 755,它解决了这个问题。

于 2012-09-23T10:09:46.747 回答
4

在您的 autoload.php 中,您需要以下内容:

$loader->add('Sports',   __DIR__ . '/../src');

除非您有 Sports 进入供应商?

============================================

所以只是为了确认你有:

运动的

运动/应用

运动/应用程序/控制台

体育/src

运动/src/Sports/FrontendBundle/SportsFrontendBundle.php

运动/供应商

Windows 还是 unix?运行控制台命令时出现错误?

于 2012-09-21T19:58:05.480 回答