瀏覽代碼

Urls avec slug_producer

Ajout d'un champs "slug" aux producteurs.
Ajout systématique du slug dans les urls de l'application "producer".
refactoring
keun 6 年之前
父節點
當前提交
b38ed5ba17
共有 11 個檔案被更改,包括 4052 行新增13 行删除
  1. +6
    -2
      common/config/bootstrap.php
  2. +4
    -2
      common/helpers/Url.php
  3. +7
    -6
      common/models/Etablissement.php
  4. +15
    -0
      console/migrations/m180312_174327_slug_producer.php
  5. +1
    -0
      frontend/models/SignupForm.php
  6. +16
    -0
      producer/components/ProducerUrlManager.php
  7. +1
    -1
      producer/components/ProducerView.php
  8. +2
    -1
      producer/config/main.php
  9. 二進制
      producer/runtime/cache/96/963454f612a8b5fb4a63ba1e97f028a1.bin
  10. +3999
    -0
      producer/runtime/logs/app.log
  11. +1
    -1
      producer/views/layouts/main.php

+ 6
- 2
common/config/bootstrap.php 查看文件

@@ -29,10 +29,14 @@ Import::using('backend\models\*');
Import::using('common\controllers\*');
Import::using('frontend\controllers\*');
Import::using('backend\controllers\*');
Import::using('producer\controllers\*');

// helpers
Import::using('common\helpers\*');

// pdf
Import::using('kartik\mpdf\Pdf');
// components
Import::using('common\components\*');
Import::using('producer\components\*');

// pdf
Import::using('kartik\mpdf\Pdf');

+ 4
- 2
common/helpers/Url.php 查看文件

@@ -8,8 +8,6 @@

namespace common\helpers;

use yii ;

class Url
{
public static function frontend($action = '')
@@ -112,4 +110,8 @@ class Url
}
}
}
public static function slugify($string) {
return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $string)));
}
}

+ 7
- 6
common/models/Etablissement.php 查看文件

@@ -50,11 +50,11 @@ class Etablissement extends \yii\db\ActiveRecord {
$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.');
}
}],
[['description', 'infos_commande'], 'string'],
[['solde_negatif', 'credit_pain', 'actif'], 'boolean'],
[['nom', 'siret', 'logo', 'photo', 'code_postal', 'ville', 'code'], 'string', 'max' => 255],
['prix_libre', 'double'],
['prix_libre', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
[['description', 'infos_commande','slug'], 'string'],
[['solde_negatif', 'credit_pain', 'actif'], 'boolean'],
[['nom', 'siret', 'logo', 'photo', 'code_postal', 'ville', 'code'], 'string', 'max' => 255],
['prix_libre', 'double'],
['prix_libre', 'compare', 'compareValue' => 0, 'operator' => '>=', 'type' => 'number', 'message' => 'Prix libre doit être supérieur ou égal à 0'],
];
}

@@ -78,7 +78,8 @@ class Etablissement extends \yii\db\ActiveRecord {
'credit_pain' => 'Crédit pain',
'actif' => 'Actif',
'date_creation' => 'Date de création',
'infos_commande' => 'Informations'
'infos_commande' => 'Informations',
'slug' => 'Slug',
];
}


+ 15
- 0
console/migrations/m180312_174327_slug_producer.php 查看文件

@@ -0,0 +1,15 @@
<?php

use yii\db\Migration;
use yii\db\Schema;

class m180312_174327_slug_producer extends Migration {

public function up() {
$this->addColumn('etablissement','slug',Schema::TYPE_STRING);
}

public function down() {
$this->dropColumn('etablissement','slug');
}
}

+ 1
- 0
frontend/models/SignupForm.php 查看文件

@@ -161,6 +161,7 @@ class SignupForm extends Model {
$etablissement->heure_limite_commande = 20;
$etablissement->delai_commande = 1;
$etablissement->gratuit = 1;
$etablissement->slug = \common\helpers\Url::slugify($this->nom_magasin) ;

// génération d'un code
do {

+ 16
- 0
producer/components/ProducerUrlManager.php 查看文件

@@ -0,0 +1,16 @@
<?php

namespace producer\components ;

class ProducerUrlManager extends \yii\web\UrlManager {
public function createUrl($params) {
if(!is_array($params))
$params = [$params] ;
$params['slug_producer'] = Yii::$app->getRequest()->getQueryParam('slug_producer') ;
return parent::createUrl($params) ;
}
}

+ 1
- 1
producer/components/ProducerView.php 查看文件

@@ -9,7 +9,7 @@ class ProducerView extends \yii\web\View {
var $subtitle ;
public function getProducer() {
return Etablissement::findOne(Yii::$app->getRequest()->getQueryParam('id_producer')) ;
return Etablissement::findOne(['slug' => Yii::$app->getRequest()->getQueryParam('slug_producer')]) ;
}
public function setTitle($title, $icon = '') {

+ 2
- 1
producer/config/main.php 查看文件

@@ -42,11 +42,12 @@ return [
'class' => 'producer\components\ProducerView',
],
'urlManager' => [
'class' => 'producer\components\ProducerUrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => false,
'rules' => [
'<id_producer:\d+>/<controller>/<action>' => '<controller>/<action>'
'<slug_producer:\w+>/<controller>/<action>' => '<controller>/<action>',
],
],
],

二進制
producer/runtime/cache/96/963454f612a8b5fb4a63ba1e97f028a1.bin 查看文件


+ 3999
- 0
producer/runtime/logs/app.log
文件差異過大導致無法顯示
查看文件


+ 1
- 1
producer/views/layouts/main.php 查看文件

@@ -46,7 +46,7 @@ $producer = $this->getProducer() ;
<nav id="main-nav">
<a id="user" href="#"><span class="glyphicon glyphicon-user"></span> <span class="caret"></span></a>
<ul class="nav nav-pills">
<li><a href="<?php echo Yii::$app->urlManager->createUrl('producer/index'); ?>"><span class="glyphicon glyphicon-th-large"></span> Accueil</a></li>
<li><a href="<?php echo Yii::$app->urlManager->createUrl(['producer/index']); ?>"><span class="glyphicon glyphicon-th-large"></span> Accueil</a></li>
<li><a href="<?php echo Yii::$app->urlManager->createUrl('commande/index'); ?>"><span class="glyphicon glyphicon-plus"></span> Commander</a></li>
<li><a href="<?php echo Yii::$app->urlManager->createUrl('producer/index'); ?>"><span class="glyphicon glyphicon-folder-open"></span> Historique</a></li>
<li><a href="<?php echo Yii::$app->urlManager->createUrl('producer/index'); ?>"><span class="glyphicon glyphicon-euro"></span> Crédit</a></li>

Loading…
取消
儲存