【问题标题】:Installing Doctrine extensions in a Symfony 2 project causes Fatal Error在 Symfony 2 项目中安装 Doctrine 扩展会导致致命错误
【发布时间】:2015-02-06 18:46:51
【问题描述】:

问题来了:我没有成功安装 Symphony 2 的教义扩展,尤其是时间戳。我关注this tutorial

我如何进行:

我在 deps 文件中添加了这一行:

[gedmo-doctrine-extensions]
   git=http://github.com/l3pp4rd/DoctrineExtensions.git

[Stof-DoctrineExtensionsBundle]
   git=https://github.com/stof/StofDoctrineExtensionsBundle.git
   target=/bundles/Stof/DoctrineExtensionsBundle

那我进线了

./bin/vendors install --reinstall

一切都好。

然后我在相关文件中激活扩展

# config.yml
stof_doctrine_extensions:
    default_locale: fr_FR
    orm:
        default:
            timestampable: true


# AppKernel.php    
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            [...]
            new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(),
            [...]
        );

# autoload.php
use Symfony\Component\ClassLoader\UniversalClassLoader;
use Doctrine\Common\Annotations\AnnotationRegistry;

$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
    'Gedmo'            => __DIR__.'/../vendor/gedmo-doctrine-extensions/lib',
    'Stof'             => __DIR__.'/../vendor/bundles', 
    [...]
    ));

最后,我添加注释我的实体

/**
 * @var datetime $updatedAt
 *
 * @ORM\Column(name="updated_at", type="datetime")
 * @Gedmo:Timestampable(on="update")
 */
private $updatedAt;

但我有这个错误:

致命错误:在第 203 行的 /Symfony/app/cache/dev/appDevDebugProjectContainer.php 中找不到类 'Gedmo\Timestampable\TimestampableListener'

我做错了什么?

【问题讨论】:

  • 教程说你必须使用` instead of :`。这样做并清除缓存。
  • @greg0ire。我不敢相信我在那个愚蠢的错误上浪费了 2 个小时。谢谢大家。这行得通...
  • 我在评论中尝试了一些格式,但反斜杠似乎避开了反引号,我的意思是“\”而不是 :
  • 我有第二个错误,命名空间 Gedmo 不好,我编辑了。所以我认为真正的错误是在那一行:'Gedmo' => __DIR__.'/../vendor/doctrine-extensions/lib',但是如果我把@Gedmo:Timestampable而不是@Gedmo\Timestampable,它也不起作用

标签: php symfony doctrine-orm doctrine-extensions stofdoctrineextensions


【解决方案1】:

使用@Gedmo\Timestampable(on="update") 并在注册命名空间时放置正确的路径似乎可以解决问题。

【讨论】:

    【解决方案2】:

    适用于 Symfony 2.0.x 和 Doctrine 2.1.x。您需要在 deps 中指定扩展的兼容版本的项目,这对我有用:

    [DoctrineExtensions]
        git=https://github.com/l3pp4rd/DoctrineExtensions.git
        target=/gedmo-doctrine-extensions
        version=origin/doctrine2.1.x
    
    [StofDoctrineExtensionsBundle]
        git=https://github.com/stof/StofDoctrineExtensionsBundle.git
        target=/bundles/Stof/DoctrineExtensionsBundle
        version=1.0.2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-16
      • 1970-01-01
      • 2014-12-01
      • 2014-05-06
      • 1970-01-01
      相关资源
      最近更新 更多