Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/yiier/yii2-seo

SEO For Yii2
https://github.com/yiier/yii2-seo

yii2-extension yii2-seo

Last synced: about 2 months ago
JSON representation

SEO For Yii2

Awesome Lists containing this project

README

        

SEO For Yii2
============
Library for working with SEO parameters of models

[![Latest Stable Version](https://poser.pugx.org/yiier/yii2-seo/v/stable)](https://packagist.org/packages/yiier/yii2-seo)
[![Total Downloads](https://poser.pugx.org/yiier/yii2-seo/downloads)](https://packagist.org/packages/yiier/yii2-seo)
[![Latest Unstable Version](https://poser.pugx.org/yiier/yii2-seo/v/unstable)](https://packagist.org/packages/yiier/yii2-seo)
[![License](https://poser.pugx.org/yiier/yii2-seo/license)](https://packagist.org/packages/yiier/yii2-seo)

Installation
------------

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist yiier/yii2-seo "*"
```

or add

```
"yiier/yii2-seo": "*"
```

to the require section of your `composer.json` file.

Configuration
-----

change your config file

```php
[
'view' => [
'as seo' => [
'class' => 'yiier\seo\SeoViewBehavior',
'names' => [

'keywords' => 'blog,forecho',
'author' => getenv('APP_NAME'),
],
'properties' => [
[
'property' => ['title', 'og:title'],
'content' => function () {
return ' tag1, tag2';
},
],
'title1' => 'title'
],
]
]
]
];
```

In model file add seo model behavior:

```php
[
'class' => 'yiier\seo\SeoModelBehavior',
'names' => [
'viewport' => function (self $model) {
return $model->title . ', tag1, tag2';
},
'keywords' => 'blog,forecho',
'author' => 'author', // model field
],
'properties' => [
[
'property' => ['title', 'og:title'],
'content' => function (self $model) {
return $model->title . ', tag1, tag2';
},
],
'title1' => 'title',
[
'property' => 'description',
'content' => function (self $model) {
return $model->title . ', tag1, tag2';
},
],
],
],
];
}
```

PHPdoc for model:

```
/**
* @property \yiier\seo\SeoModelBehavior $seoBehavior
* @method \yiier\seo\SeoModelBehavior getSeoBehavior()
*/
```

Change `/frontend/views/layouts/main.php`:

```php


= Html::encode($this->title) ?>

renderMetaTags(); ?>
...

```

Usage
-----

In "view.php" file for model:

```php
// set SEO:meta data for current page
$this->setSeoData($model->getSeoBehavior());
```

or in controller:

```php
Yii::$app->view->setSeoData($model->getSeoBehavior());
```

Simple url rules example in '/frontend/config/main.php':

```php
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'//' => '/',
'///' => '//',
'post/' => 'post/',
'post/' => 'post/view',
],
],
```

Reference
-----

[demisang/yii2-seo](https://github.com/demisang/yii2-seo)