在Symfony 2项目中安装Doctrine扩展会导致致命错误
问题描述:
以下是问题:我没有成功安装symphony 2的doctrine扩展,特别是timestampable。我跟着this tutorial在Symfony 2项目中安装Doctrine扩展会导致致命错误
我如何着手:
我在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;
但我有此错误:
Fatal error: Class 'Gedmo\Timestampable\TimestampableListener' not found in /Symfony/app/cache/dev/appDevDebugProjectContainer.php on line 203
我该怎么办错了?
答
使用@Gedmo\Timestampable(on="update")
并在注册名称空间时放置正确的路径似乎可以解决问题。
答
对于Symfony 2.0.x和Doctrine 2.1.x.你需要指定扩展的兼容版本,这是对我有用的工具:
[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
本教程说你必须使用'\'而不是':'。这样做并清除缓存。 – greg0ire
@ greg0ire。我不敢相信我在那个愚蠢的错误上失去了2个小时。感谢所有。这是有效的... – JiDai
我在我的评论中尝试了一些格式,但反斜杠似乎逃避反向,我的意思是“\”而不是':' – greg0ire