【发布时间】: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