繁体   English   中英

如何使用教义2.3 / symfony 3.4获得可扩展的DoctrineExtensions?

[英]How to get DoctrineExtensions sluggable working with doctrine 2.3 / symfony 3.4?

我试图在我的项目中进行缓慢的理论扩展。 我遵循在Internet上找到的设置步骤,但似乎不起作用(@Gedmo \\ Slug似乎没有被调用/触发)。

目的是要塞一个职位。

我在PHP 7.1上使用Symfony 3.4和Doctrine 2.3。

是否有人知道如何进行这项工作,我将不胜感激。

我在AppKernel中添加了捆绑包( new Stof\\DoctrineExtensionsBundle\\StofDoctrineExtensionsBundle()

这是我的其他项目文件:

composer.json

    "require": {
        "php": ">=5.5.9",
        "doctrine/doctrine-bundle": "^1.6",
        "doctrine/orm": "^2.5",
        "incenteev/composer-parameter-handler": "^2.0",
        "sensio/distribution-bundle": "^5.0.19",
        "sensio/framework-extra-bundle": "^5.0.0",
        "symfony/monolog-bundle": "^3.1.0",
        "symfony/polyfill-apcu": "^1.0",
        "symfony/swiftmailer-bundle": "^2.6.4",
        "symfony/symfony": "3.4.*",
        "twig/twig": "^1.0||^2.0",
        "stof/doctrine-extensions-bundle": "^1.3.0",
        "gedmo/doctrine-extensions": "^2.3.4"
    },

应用程序/配置/ config.yml

# Stof\DoctrineExtensionsBundle configuration
stof_doctrine_extensions:
    orm:
        default:
            sluggable: true

SRC / XXX / xxxBundle /实体/ Advert.php

use Gedmo\Mapping\Annotation as Gedmo;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;

 * @ORM\HasLifecycleCallbacks()
 */
class Advert
{


/**
 * @var string
 *
 * @ORM\Column(name="title", type="string", length=255)
 */
private $title;

/**
 * @var string
 * 
 * @Gedmo\Slug(fields={"title"})
 * @ORM\Column(name="slug", type="string", length=255, unique=true, nullable=true)
 */
private $slug; 

我只是想通!

我忘记将服务添加到捆绑包中。

因此,在我的services.yml中,我添加了以下几行:

gedmo.listener.sluggable:
    class: Gedmo\Sluggable\SluggableListener
    tags:
        - { name: doctrine.event_subscriber, connection: pgsql }
    calls:
        - [ setAnnotationReader, [ "@annotation_reader" ] ]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM