]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Правки по обновлению slug
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 12 Feb 2025 11:23:46 +0000 (14:23 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 12 Feb 2025 11:23:46 +0000 (14:23 +0300)
erp24/controllers/WikiCategoryController.php
erp24/controllers/WikiController.php

index 3adffe63d8237d270c83f1074024e1f5e44f2ea6..ccd4d1b33d2ddb8909c259125cd137c4a5a3b0c2 100644 (file)
@@ -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', [
index 7a46849f18177fd82fa31554e26274dd468d833f..50d7d5ac185d0d1c5f2ca4a4aa9d7a38f169da16 100644 (file)
@@ -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', [