Browse Source

Urls avec slug_producer

Ajout d'un champs "slug" aux producteurs.
Ajout systématique du slug dans les urls de l'application "producer".
dev
keun 6 years ago
parent
commit
b38ed5ba17
11 changed files with 4052 additions and 13 deletions
  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. BIN
      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 View File

Import::using('common\controllers\*'); Import::using('common\controllers\*');
Import::using('frontend\controllers\*'); Import::using('frontend\controllers\*');
Import::using('backend\controllers\*'); Import::using('backend\controllers\*');
Import::using('producer\controllers\*');


// helpers // helpers
Import::using('common\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 View File



namespace common\helpers; namespace common\helpers;


use yii ;

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

+ 7
- 6
common/models/Etablissement.php View File

$this->addError($attribute, 'Ce code est déjà utilisé par un autre producteur.'); $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'],
]; ];
} }


'credit_pain' => 'Crédit pain', 'credit_pain' => 'Crédit pain',
'actif' => 'Actif', 'actif' => 'Actif',
'date_creation' => 'Date de création', 'date_creation' => 'Date de création',
'infos_commande' => 'Informations'
'infos_commande' => 'Informations',
'slug' => 'Slug',
]; ];
} }



+ 15
- 0
console/migrations/m180312_174327_slug_producer.php View File

<?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 View File

$etablissement->heure_limite_commande = 20; $etablissement->heure_limite_commande = 20;
$etablissement->delai_commande = 1; $etablissement->delai_commande = 1;
$etablissement->gratuit = 1; $etablissement->gratuit = 1;
$etablissement->slug = \common\helpers\Url::slugify($this->nom_magasin) ;


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

+ 16
- 0
producer/components/ProducerUrlManager.php View File

<?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 View File

var $subtitle ; var $subtitle ;
public function getProducer() { 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 = '') { public function setTitle($title, $icon = '') {

+ 2
- 1
producer/config/main.php View File

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

BIN
producer/runtime/cache/96/963454f612a8b5fb4a63ba1e97f028a1.bin View File


+ 3999
- 0
producer/runtime/logs/app.log
File diff suppressed because it is too large
View File


+ 1
- 1
producer/views/layouts/main.php View File

<nav id="main-nav"> <nav id="main-nav">
<a id="user" href="#"><span class="glyphicon glyphicon-user"></span> <span class="caret"></span></a> <a id="user" href="#"><span class="glyphicon glyphicon-user"></span> <span class="caret"></span></a>
<ul class="nav nav-pills"> <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('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-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> <li><a href="<?php echo Yii::$app->urlManager->createUrl('producer/index'); ?>"><span class="glyphicon glyphicon-euro"></span> Crédit</a></li>

Loading…
Cancel
Save