Symfony2 - 在生产环境下找不到类

9

我正在Symfony 2.1中创建新项目。我想检查我的应用程序是否可以在我的服务器上正确运行,因此我复制了所有文件,清除了缓存并设置了权限。在本地开发环境中一切都很好,但是当我在服务器上请求“在线-prod”版本时,我遇到了一个错误:

Fatal error: Class 'Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle' not found in /www/gastlich_www/www/livescore.gastlich.iq.pl/app/AppKernel.php on line 25

我找到了一些关于这个问题的信息,但是所有的信息都与将命名空间从Symfony\Bundle更改为Doctrine\Bundle和Symfony 2.0有关。

所以我检查了我的AppKernel.php文件,我的bundle路径是正确的。

我的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.*",
    "doctrine/orm": ">=2.2.3,<2.4-dev",
    "doctrine/doctrine-bundle": "1.0.*",
    "twig/extensions": "1.0.*",
    "symfony/assetic-bundle": "2.1.*",
    "symfony/swiftmailer-bundle": "2.1.*",
    "symfony/monolog-bundle": "2.1.*",
    "sensio/distribution-bundle": "2.1.*",
    "sensio/framework-extra-bundle": "2.1.*",
    "sensio/generator-bundle": "2.1.*",
    "jms/security-extra-bundle": "1.2.*",
    "jms/di-extra-bundle": "1.1.*",
    "stof/doctrine-extensions-bundle": "dev-master",
    "doctrine/doctrine-fixtures-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"
    ]
},
"minimum-stability": "dev",
"extra": {
    "symfony-app-dir": "app",
    "symfony-web-dir": "web"
}

还有AppKernel.php的配置:

<?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 Acme\StoreBundle\AcmeStoreBundle(),
            new Livescore\StatsBundle\LivescoreStatsBundle(),
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle()
        );

        if (in_array($this->getEnvironment(), array('dev', 'test'))) {
            $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');
    }
}

我试图找出问题所在,于是我在AppKernel.php中删除了这个bundle,结果出现了致命错误:

Fatal error: Class 'Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle' not found in /www/gastlich_www/www/livescore.gastlich.iq.pl/app/AppKernel.php on line 24

我假设我只有最近两个包的问题: StofDoctrineExtensionsBundleDoctrineFixturesBundle,它们在composer.json中有dev-master版本。此时,我没有进一步的想法。我尝试谷歌这个问题,但90%的问题都是关于Symfony 2.0和移动git存储库的;/。
本地开发环境: PHP 5.4.6 Mysql 5.5.27 Apache 2.2.22 (Fedora)
我的服务器环境: PHP 5.4.6 MySql 5.0.32
非常感谢您的任何帮助。
谢谢!

这个文件(包含DoctrineFixturesBundle类)是否存在于物理上?尝试运行:php composer.phar update,看看问题是否仍然存在。 - Cyprian
嗨,我运行了compser.phar update,但是出现了“源目录有未提交的更改”的一些错误。所以我删除了这些冲突的供应商,一切都进行得很顺利。脚本没有更新任何fixtures/stof bundle。下一步是将更改复制到在线服务器上,我复制了整个应用程序目录。删除缓存后,我的应用程序在在线服务器上运行良好,我不知道问题出在哪里;/感谢您的帮助和建议 :) - Jacek Wojna
2个回答

8

在更新/安装composer之前,您需要将命令行环境设置为生产环境。

以下内容来自Symfony官方文档:

如果在此步骤中出现“类未找到”错误,则可能需要在运行此命令之前运行export SYMFONY_ENV=prod,以便post-install-cmd脚本在prod环境中运行。


1
这是正确的答案,但遗憾的是Composer在生产环境中无法与Symfony配合使用... - Matthieu Napoli

-2

app/autoload.php

use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = require __DIR__.'/../vendor/autoload.php';

// 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('Stof\DoctrineExtensionsBundle', __DIR__.'/../vendor/stof/doctrine-extensions-bundle');
$loader->add('Gedmo' , __DIR__.'/../vendor/gedmo/doctrine-extensions/lib');

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

return $loader;

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接