【问题标题】:How to get DoctrineExtensions sluggable working with doctrine 2.3 / symfony 3.4?如何让 DoctrineExtensions sluggable 与教义 2.3 / symfony 3.4 一起使用?
【发布时间】:2019-01-30 16:44:53
【问题描述】:

我尝试在我的项目中获得可扩展的原则扩展。我按照在 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"
    },

app/config/config.yml

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

src/xxx/xxxBundle/Entity/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; 

【问题讨论】:

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


    【解决方案1】:

    我只是想通了!

    我忘记在我的包中添加服务。

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

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

    【讨论】:

      猜你喜欢
      • 2012-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-25
      • 1970-01-01
      相关资源
      最近更新 更多