dev-master
9999999-dev https://github.com/pantera-digital/yii2-seoYii2 SEO module
The Requires
- php >=5.4.0
- yiisoft/yii2 *
- yiisoft/yii2-bootstrap *
yii2 seo
Yii2 SEO module
SEO-fields for your models: title, description, keywords and some others, (*1)
Run, (*2)
php composer require pantera-digital/yii2-seo "*"
Or add to composer.json, (*3)
"pantera-digital/yii2-seo": "*",
and execute:, (*4)
php composer update
ΠΠΈΠ³ΡΠ°ΡΠΈΡ:, (*5)
php yii migrate --migrationPath=vendor/pantera-digital/yii2-seo/migrations
ΠΠΎΠ΄ΡΠ»Ρ Π·Π°Π²ΠΈΡΠΈΡ ΠΎΡ https://github.com/yiisoft/yii2-twig Π΄Π»Ρ ΠΏΠΎΠ»Π½ΠΎΠΉ ΡΠ°Π±ΠΎΡΡ ΠΏΡΠ΅ΡΠ΅ΡΠΎΠ² Π½ΡΠΆΠ½ΠΎ ΡΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠΈΡΠΎΠ²Π°ΡΡ ΡΡΠΎ ΡΠ°ΡΡΠΈΡΠ΅Π½ΠΈΠ΅, (*6)
Attach behavior to your model:, (*7)
function behaviors() { return [ 'seo' => [ 'class' => 'pantera\seo\behaviors\SeoFields', ], ]; }
Example of use in view:, (*8)
if (!$title = $model->seo->title) { $title = "Buy {$model->name} in store"; } if (!$description = $model->seo->description) { $description = 'Page ' . $model->name; } if (!$keywords = $model->seo->keywords) { $keywords = ''; } $this->title = $title; $this->registerMetaTag([ 'name' => 'description', 'content' => $description, ]); $this->registerMetaTag([ 'name' => 'keywords', 'content' => $keywords, ]);
Add to your model form:, (*9)
<?=\pantera\seo\widgets\SeoForm::widget([ 'model' => $model, 'form' => $form, ]); ?>
ΠΡΠΆΠ½ΠΎ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠΈΡΡ ΠΊΠΎΠΌΠΏΠΎΠ½Π΅Π½Ρ Π² ΠΊΠΎΠ½ΡΠΈΠ³, (*10)
'components' => [ 'seo' => [ 'class' => pantera\seo\components\SeoComponent::className(), ], ]
ΠΡΠΆΠ½ΠΎ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠΈΡΡ Π² Π±ΡΡΡΡΡΠ°ΠΏ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΡ ΠΊΠ»Π°ΡΡ, (*11)
'bootstrap' => [pantera\seo\Registrar::className()],
ΠΠ»Ρ Π»ΠΎΠ³ΠΈΡΠΎΠ²Π°Π½ΠΈΡ Π½ΡΠΆΠ½ΠΎ Π² ΠΎΠ±ΡΠ°Π±ΠΎΡΡΠΈΠΊ ΠΎΡΠΈΠ±ΠΎΠΊ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ, (*12)
if ($exception instanceof NotFoundHttpException) { $logger = new pantera\seo\models\SeoNotFound(); $logger->url = Yii::$app->request->url; $logger->referrer = Yii::$app->request->referrer; $logger->ip = Yii::$app->request->getRemoteIP(); $logger->save(); }
Π ΠΌΠΎΠ΄Π΅Π»Ρ Π½ΡΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡΡ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅, (*13)
public function behaviors() { return [ [ 'class' => pantera\seo\behaviors\SlugBehavior::className(), 'attribute' => 'title', 'slugAttribute' => 'slug', ], ]; }
Π ΠΌΠΎΠ΄Π΅Π»Ρ ΠΏΠΎΠ΄ΠΊΠ»ΡΡΠΈΡΡ Π²Π°Π»ΠΈΠ΄Π°ΡΠΎΡ, (*14)
public function rules() { return [ [['slug'], pantera\seo\validators\SlugValidator::className(), 'skipOnEmpty' => false], ]; }
Π‘ΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠΈΡΠΎΠ²Π°ΡΡ ΡΠ²ΠΎΠΉ UrlManager, (*15)
Π½ΡΠΆΠ½ΠΎ ΡΠΊΠΎΠ½ΡΠΈΠ³ΡΡΠΈΡΠΎΠ²Π°ΡΡ ΡΠ°ΡΡΠΈΡΠ΅Π½ΠΈΠ΅ https://packagist.org/packages/dragonjet/yii2-opengraph, (*16)
'components' => [ 'openGraph' => [ 'class' => dragonjet\opengraph\OpenGraph::class, ], ],
Π ΠΏΠΎΠ»Π΅ Og Image Π½ΡΠΆΠ½ΠΎ Π½Π°ΠΏΠΈΡΠ°ΡΡ ΠΊΠ°ΠΊ ΠΏΠΎΠ»ΡΡΠΈΡΡ ΠΊΠ°ΡΡΠΈΠ½ΠΊΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡ twig, (*17)
Yii2 SEO module
yii2 seo