PHP code example of yiier / yii2-seo
1. Go to this page and download the library: Download yiier/yii2-seo library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yiier / yii2-seo example snippets
return [
'components' => [
'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'
],
]
]
]
];
public function behaviors()
{
return [
'seo' => [
'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';
},
],
],
],
];
}
/* @var $this \yii\web\View|\yiier\seo\SeoViewBehavior */
// set SEO:meta data for current page
$this->setSeoData($model->getSeoBehavior());
Yii::$app->view->setSeoData($model->getSeoBehavior());
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<module>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>',
'post/<action:(index|create|update|delete)>' => 'post/<action>',
'post/<title:[-\w]+>' => 'post/view',
],
],
php composer.phar