From: fomichev Date: Wed, 12 Feb 2025 11:23:46 +0000 (+0300) Subject: Правки по обновлению slug X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=918404bf5ae4ba6d67f2a9a3071cc9638980c0c4;p=erp24_rep%2Fyii-erp24%2F.git Правки по обновлению slug --- diff --git a/erp24/controllers/WikiCategoryController.php b/erp24/controllers/WikiCategoryController.php index 3adffe63..ccd4d1b3 100644 --- a/erp24/controllers/WikiCategoryController.php +++ b/erp24/controllers/WikiCategoryController.php @@ -3,6 +3,7 @@ namespace app\controllers; use Yii; +use yii\helpers\Inflector; use yii_app\records\WikiCategory; use yii\data\ActiveDataProvider; use yii\web\Controller; @@ -111,8 +112,14 @@ class WikiCategoryController extends Controller { $model = $this->findModel($id); - if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); + if ($this->request->isPost && $model->load($this->request->post())) { + $model->slug = Inflector::slug($model->title); + if ($model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } else { + Yii::error("Ошибка при сохранении: " . json_encode($model->errors)); + Yii::$app->session->setFlash('error', 'Ошибка при сохранении.'); + } } return $this->render('update', [ diff --git a/erp24/controllers/WikiController.php b/erp24/controllers/WikiController.php index 7a46849f..50d7d5ac 100644 --- a/erp24/controllers/WikiController.php +++ b/erp24/controllers/WikiController.php @@ -3,6 +3,7 @@ namespace app\controllers; use Yii; +use yii\helpers\Inflector; use yii_app\records\WikiArticle; use yii_app\records\WikiArticleSearch; use yii\web\Controller; @@ -129,10 +130,16 @@ class WikiController extends Controller { $model = $this->findModel($id); - if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { - $categorySlug = $model->category->slug; - $articleSlug = $model->slug; - return $this->redirect(['view', 'parent_cat_slug' => $categorySlug, 'article_slug' => $articleSlug]); + if ($this->request->isPost && $model->load($this->request->post())) { + $model->slug = Inflector::slug($model->title); + if ($model->save()) { + $categorySlug = $model->category->slug; + $articleSlug = $model->slug; + return $this->redirect(['view', 'parent_cat_slug' => $categorySlug, 'article_slug' => $articleSlug]); + } else { + Yii::error("Ошибка при сохранении: " . json_encode($model->errors)); + Yii::$app->session->setFlash('error', 'Ошибка при сохранении.'); + } } return $this->render('update', [