Generating doctrine slugs manually

后端 未结 3 563
独厮守ぢ
独厮守ぢ 2021-01-20 05:27

I\'m using sluggable behavior in my Symfony2 project, but now I would like to make many slugs for one page, based on different texts (current title, old title(s), users text

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 05:42

    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;
    

提交回复
热议问题