How to generate URL slug

Does Yii2 include any function to generate URL slug from let’s say user submitted title?

For example:

Title: My first blog post

URL slug: my-first-blog-post

Hello,

yes you can generate SEF URL in YII

you just need to create that rule in URLMANAGER such as this

‘<id:\w+>’ => ‘<controller>/slug’,

in your controller you must also have a function with appropriate name and input

Thanks. Not sure if this is what I want or I don’t get it. I just want to be able to generate human friendly URL string. Don’t need any routing rules & stuff. Can you explain a bit more how to use UrlManager for this?

In Codeigniter I would simply use this function url_title() (https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html)

There’s no built in functionality, but there are a number of extensions which do this.

Have a look at this one.

EDIT:

Sorry, I didn’t realise that this was a Yii 2 topic. See if the SluggableBehavior class helps.

Thanks Keith!