2017 © Pedro PelΓ‘ez
 

yii2-extension yii2-seo

Yii2 SEO module

image

pantera-digital/yii2-seo

Yii2 SEO module

  • Thursday, March 22, 2018
  • by webmayak
  • Repository
  • 2 Watchers
  • 0 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 63 % Grown

The README.md

Yii2 SEO module

SEO-fields for your models: title, description, keywords and some others, (*1)

Install

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)

Usage

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, ]);

Widgets

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()],

Not found

Для логирования Π½ΡƒΠΆΠ½ΠΎ Π² ΠΎΠ±Ρ€Π°Π±ΠΎΡ‚Ρ‡ΠΈΠΊ ошибок Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ, (*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();
}

Slug

Π’ модСль Π½ΡƒΠΆΠ½ΠΎ Π΄ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅, (*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)

ΠœΠΎΠ΄ΡƒΠ»ΡŒ ΠΈΠΌΠ΅ΠΈΡ‚ Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎΡΡ‚ΡŒ рСгистрации Open Graph Ρ‚Π΅Π³ΠΎΠ²

Π½ΡƒΠΆΠ½ΠΎ ΡΠΊΠΎΠ½Ρ„ΠΈΠ³ΡƒΡ€ΠΈΡ€ΠΎΠ²Π°Ρ‚ΡŒ Ρ€Π°ΡΡˆΠΈΡ€Π΅Π½ΠΈΠ΅ https://packagist.org/packages/dragonjet/yii2-opengraph, (*16)

'components' => [
    'openGraph' => [
        'class' => dragonjet\opengraph\OpenGraph::class,
    ],
],

Π’ ΠΏΠΎΠ»Π΅ Og Image Π½ΡƒΠΆΠ½ΠΎ Π½Π°ΠΏΠΈΡΠ°Ρ‚ΡŒ ΠΊΠ°ΠΊ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ ΠΊΠ°Ρ€Ρ‚ΠΈΠ½ΠΊΡƒ ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΡƒΡ twig, (*17)

The Versions

22/03 2018

dev-master

9999999-dev https://github.com/pantera-digital/yii2-seo

Yii2 SEO module

  Sources   Download

The Requires

 

yii2 seo