问题在于:我没有成功安装symphony 2的doctrine扩展,特别是timestampable。我关注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'
我做错了什么?
答案 0 :(得分:1)
使用@Gedmo\Timestampable(on="update")
并在注册命名空间时放置正确的路径似乎可以解决问题。
答案 1 :(得分:0)
对于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