Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/yiier/yii2-seo
- Owner: yiier
- Created: 2020-02-06T06:10:36.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-02-06T06:40:56.000Z (almost 5 years ago)
- Last Synced: 2024-04-14T09:58:38.155Z (8 months ago)
- Topics: yii2-extension, yii2-seo
- Language: PHP
- Homepage:
- Size: 2.93 KB
- Stars: 1
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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)