在Symfony 2项目中安装Doctrine扩展会导致致命错误

时间:2021-07-15 20:30:15

Here is the problem : I don't succeed to install doctrine extensions with symphony 2, especially timestampable. I follow this tutorial

问题是:我没有成功安装symphony 2的doctrine扩展,特别是timestampable。我按照本教程

How I proceed :

我如何进行:

I add this lines in deps file :

我在deps文件中添加以下行:

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

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

Then I enter the line

然后我进入该行

./bin/vendors install --reinstall

All is fine.

一切皆好。

Then I activate extensions in concerned files

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

# 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', 
    [...]
    ));

At last, I add annotate my entity

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

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

But I have this error :

但我有这个错误:

Fatal error: Class 'Gedmo\Timestampable\TimestampableListener' not found in /Symfony/app/cache/dev/appDevDebugProjectContainer.php on line 203

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

What do I do wrong ?

我做错了什么?

2 个解决方案

#1


1  

Using @Gedmo\Timestampable(on="update") and putting the right path when registering the namespace seems to solve the problem.

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

#2


0  

For Symfony 2.0.x and Doctrine 2.1.x. projects you'll need to specify the compatible versions of the extensions in deps, this is what worked for me:

对于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

#1


1  

Using @Gedmo\Timestampable(on="update") and putting the right path when registering the namespace seems to solve the problem.

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

#2


0  

For Symfony 2.0.x and Doctrine 2.1.x. projects you'll need to specify the compatible versions of the extensions in deps, this is what worked for me:

对于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