Answer the question
In order to leave comments, you need to log in
Slug not generated when post is created?
I use Sluggable Behavior, I want a unique slug to be automatically generated when creating an entry:
public function behaviors()
{
return [
[
'class' => SluggableBehavior::className(),
'attribute' => 'name',
'ensureUnique' => true
],
'timestampBehavior' => [
'class' => TimestampBehavior::className(),
],
];
}
if ($model->load(Yii::$app->request->post())) {
$model->user_id = Yii::$app->user->id;
$model->status = Place::STATUS_ACTIVE;
// $model->slug = \yii\helpers\BaseInflector::slug($model->name); // Саначала решил проблему этим, но это генерирует не уникальный слаг
if($model->save(false)) {
return $this->redirect(['/'.$model->slug]);
}
}
SQLSTATE[HY000]: General error: 1364 Field 'slug' doesn't have a default value
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question