May be I have misunderstood the whole usage of the behaviour. So I will post again with more details.
I have in model Blog the following code
public function behaviors()
{
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'title',
// In case of attribute that contains slug has different name
// 'slugAttribute' => 'alias',
/*'value' => function ($event) {
return str_replace(' ', '-', $this->blog->name);
}*/
],
];
}
I supposed it would add the attribute slug to model, it didn’t. So I defined a public attribute $slug and added to safe in model rules.
Still when I use with above code on the view, slug is empty. What am I doing wrong here?
I think it should work when you have set a public variable with the name slug. But I am not sure it is called on loading a model. Perhaps it only is called on a save?
If you don’t want to save it to the database, what do you want to do with it?
I have tried everything that should work but does not. My Controllers whose URL am rewritting using those rules are in module called blog. Is there supposed to be a special way of treating URL in module? AFAIK it should not be a problem but then, I might be wrong!