How to use uniqueSlugGenerator?

Hello people!

I am kinda new to Yii2 and PHP and I am having trouble understanding how uniqueSlugGenerator property of SluggableBehavior is used.

I want to generate a unique slug like this,

example.com/user/(randomstring)-username

or

example.com/user/(id)-username

Can anybody please explain with examples if possible?.

my current config looks like this,



        'urlManager' => [


            'baseUrl' => $baseUrl,


            'enablePrettyUrl' => true,


            'showScriptName' => false,


            'rules' => array(


            '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',


            'user/<slug>' => 'user/profile'


            )


        ],

and user model



    public function behaviors()


    {


        return [


            [


                'class' => SluggableBehavior::className(),


                'attribute' => 'username',


                'ensureUnique' => true,


                'immutable' => true


            ],


        ];


    }

Thanks!