Generating doctrine slugs manually

邮差的信 提交于 2019-12-01 21:38:30
Radzikowski

I found solution by accident here. Code:

use Gedmo\Sluggable\Util as Sluggable;    

$string = 'My own text!';
$slug = Sluggable\Urlizer::urlize($string, '-');
    if(empty($slug)) // if $string is like '=))' or 'トライアングル・サービス' an empty slug will be returned, that causes troubles and throws no exception
        echo 'error, empty slug!!!';
    else
        echo $slug;

Find the doctrine code for generating a slug here: l3pp4rd/DoctrineExtensions. Playing around with that class could do as you desire but you will probable need to create your own service to implement an easy use as you want. See the Service Container section of the docs for more details about services.

Mathieu Mlr

The Sluggable\Urlizer::urlize seems to replace ' with -. I had to use Sluggable\Urlizer::transliterate to be closer to the SluggableListener behaviour.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!