From 918404bf5ae4ba6d67f2a9a3071cc9638980c0c4 Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 12 Feb 2025 14:23:46 +0300 Subject: [PATCH] =?utf8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF?= =?utf8?q?=D0=BE=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D1=8E=20slug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/controllers/WikiCategoryController.php | 11 +++++++++-- erp24/controllers/WikiController.php | 15 +++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) 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', [ -- 2.39.5