sieulog
(Tuan)
March 16, 2016, 11:50am
1
Hello!
I want make slug with title if Slug field is empty.
I can’t found the way resolve problem.
---------Explain---------
If create or update a post. If I type Title but I don’t enter any words in field slug. When I submit to save post, slug will make with Title field
jacmoe
(Jacob Moen)
March 19, 2016, 9:50pm
3
The whole point of the sluggable behavior is that it generates the slug automatically - usually from the title.
How did you set it up?
sieulog
(Tuan)
March 20, 2016, 3:59am
4
My config:
public function behaviors()
{
return [
...
[
'class' => SluggableBehavior::className(),
'attribute' => 'title',
'immutable' => true
],
];
}
I understand, but I want User can manualy make slug.
jacmoe
(Jacob Moen)
March 20, 2016, 4:23am
5
Then do not use the behavior but use the code instead to check if the user provided a valid slug, and if not then generate one. Or modify the invalid slug given so that it becomes valid.
sieulog
(Tuan)
March 20, 2016, 2:32pm
6
I can make a function check it in controller before save. But I don’t know Sluggable Behavior supported or not.