mirkhamidov/yii2-seo

Handy module for managing seo attributes

Installs: 10

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2017-04-11 17:11 UTC

This package is auto-updated.

Last update: 2024-11-29 05:03:35 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

composer require mirkhamidov/yii2-seo "@dev"

or add

"mirkhamidov/yii2-seo": "@dev"

to the require section of your composer.json file.

for run migrations add to your console config migrationNamespaces

<?php
return [
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationNamespaces' => [
                'mirkhamidov\seo\migrations',
            ],
        ],
    ],
];

just run

./yii migrate

Configure

Backend (manage)

add module to your config

return [
    ...,
    'modules' => [
        ...,
        'seo' => 'mirkhamidov\seo\Module',
    ],
    ...,
];

Routes to Menu

  • seo/page - to add new config for route
  • seo/attribute - to add more attributes

Frontend

add bootstap and component to your config

return [
    'bootstrap' => [
        ..., 
        'seo',
    ],
    ...,
    'components' => [
        ...,
        'seo' => [
            'class' => 'mirkhamidov\seo\components\Seo'
        ],
    ],
    ...,
];

Layouts

title

<?php
if (is_null(Yii::$app->seo->tag('title'))) {
    echo '<title>' . Html::encode($this->title) . ' - ' . Yii::$app->name . '</title>';
} else {
    echo '<title>' . Html::encode(Yii::$app->seo->tag('title')) . '</title>';
}
?>

h1

<h1 class="main-title">
<?php
    if (is_null(Yii::$app->seo->tag('h1'))) {
        echo Html::encode($this->title);
    } else {
        echo Html::encode(Yii::$app->seo->tag('h1'));
    }
?>
</h1>