Manual doctrine pools

I use sluggable behavior in my Symfony2 project, but now I would like to make a lot of slugs for one page based on different texts (current name, old title, user text from form input) and save this in another table. And my question is: how do I manually use doctrine extensions for any text? I can not find it anywhere. Ideally, something like:

/* careful - it not a real, working code! */ $sluggable = new DoctrineSluggable(); $slug = $sluggable->generate('My own text!'); echo $slug; // my-own-text 
+2
source share
2 answers

Find the doctrine code for generating the bullet here: l3pp4rd / DoctrineExtensions . A game with this class could do as you please, but you probably want to create your own service in order to implement the easy use of your choice. For more information about services, see the Service Container section in the docs.

+1
source

I found a 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; 
+12
source

Source: https://habr.com/ru/post/976871/


All Articles