Logo Questions Linux Laravel Mysql Ubuntu Git Menu

Generating doctrine slugs manually

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 from form input), and keep it in another table. And my question is - how to manually use doctrine extensions for any text? I can't find it anywhere. Perfect would be something like:

/* careful - it's not a real, working code! */
$sluggable = new DoctrineSluggable();
$slug = $sluggable->generate('My own text!');
echo $slug; // my-own-text
like image 760
Radzikowski Avatar asked Nov 30 '22 12:11


2 Answers

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!!!';
        echo $slug;
like image 100
Radzikowski Avatar answered Dec 18 '22 12:12


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.

like image 32
ferdynator Avatar answered Dec 18 '22 12:12