1. Go to this page and download the library: Download romi45/yii2-seo-behavior 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/ */
romi45 / yii2-seo-behavior example snippets
use romi45\seoContent\components\SeoBehavior;
class Post extends ActiveRecord
{
/**
* @inheritdoc
*/
public function behaviors() {
return [
[
'seo' => [
'class' => SeoBehavior::className(),
// This is default values. Usually you can not specify it
'titleAttribute' => 'seoTitle',
'keywordsAttribute' => 'seoKeywords',
'descriptionAttribute' => 'seoDescription'
],
],
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
// ...
[['seoTitle', 'seoKeywords', 'seoDescription'], 'safe'],
[['seoTitle'], 'checkSeoTitleIsGlobalUnique'], // It recommends for title to be unique for every page. You can ignore this recommendation - just delete this rule.
// ...
];
}
}
use romi45\seoContent\components\SeoContentHelper;
/**
* You can also user partial register functions
* @see SeoContentHelper::registerAll()
*/
SeoContentHelper::registerAll($model);