Ajout d'un champs "slug" aux producteurs. Ajout systématique du slug dans les urls de l'application "producer".dev
@@ -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\*'); | |||
Import::using('kartik\mpdf\Pdf'); | |||
// components | |||
Import::using('common\components\*'); | |||
Import::using('producer\components\*'); | |||
Import::using('kartik\mpdf\Pdf'); |
@@ -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))); | |||
} | |||
} |
@@ -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', | |||
]; | |||
} | |||
@@ -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'); | |||
} | |||
} |
@@ -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 { |
@@ -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) ; | |||
} | |||
} |
@@ -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 = '') { |
@@ -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>', | |||
], | |||
], | |||
], |
@@ -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> |