2017 © Pedro Peláez
 

yii2-extension yii2-seo-behavior

Seo behavior for Yii2 models and meta tags helper with patterns using possibility

image

romi45/yii2-seo-behavior

Seo behavior for Yii2 models and meta tags helper with patterns using possibility

  • Saturday, June 2, 2018
  • by romi45
  • Repository
  • 2 Watchers
  • 3 Stars
  • 174 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 11 Versions
  • 4 % Grown

The README.md

Seo meta contents behavior for Yii 2

This extension provides behavior functions for seo meta tags and title tag support. Also provides view helper for registering meta tags and title., (*1)

Installation

My favorite way to install this extension is through composer., (*2)

Either run, (*3)

$ composer require romi45/yii2-seo-behavior:~1.0

or add, (*4)

"romi45/yii2-seo-behavior": "~1.0"

to the require section of your composer.json file., (*5)

and then run migration, (*6)

php yii migrate --migrationPath="@vendor/romi45/yii2-seo-behavior/migrations"

Configuring

First you need to configure your model:, (*7)

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.
            // ...
        ];
    }
}

Now you are ready to use it on form, (*8)


= $form->field($model, 'seoTitle')->textInput(); ?> = $form->field($model, 'seoKeywords')->textInput(); ?> = $form->field($model, 'seoDescription')->textarea(); ?>

As you can see, seoTitle, seoKeywords and seoDescription is the attributes (by default) from which we can access SEO content of model., (*9)

Once you post a form with the above fields, they will be automatically saved and linked to our Post model., (*10)

To register meta tags and set title in view use following code:, (*11)

use romi45\seoContent\components\SeoContentHelper;

/**
 * You can also user partial register functions
 * @see SeoContentHelper::registerAll()
 */
SeoContentHelper::registerAll($model);

Do not forget about title tag in layout., (*12)

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

Patterns

You can use patterns in values and it will replaced with some model properties, application config property, application parameter or view parameter type will defined by prefixes., (*13)

Model Attribute, (*14)

%%model_ATTRIBUTE_NAME%%

For example %%model_title%% will replace with php $model->title, (*15)

Application Global Config Attribute, (*16)

%%appConfig_ATTRIBUTE_NAME%%

For example %%appConfig_name%% will replace with php Yii::$app->name, (*17)

Application Global Parameter Attribute, (*18)

%%appParam_ATTRIBUTE_NAME%%

For example %%appParam_contactEmail%% will replace with php Yii::$app->params['contactEmail''], (*19)

View Global Parameter Attribute, (*20)

%%viewParam_ATTRIBUTE_NAME%%

For example %%viewParam_contactEmail%% will replace with php Yii::$app->view->params['contactEmail'']., (*21)

Separator, (*22)

%%sep%%

By default separator pattern replaced with '-'. If you want to use another value for separator you need to identify php Yii::$app->view->params['titleSeparator''] param., (*23)

Hint: instead of 'titleSeparator' you can use romi45\seoContent\components\SeoPatternHelper::SEPARATOR_VIEW_PARAMETER_KEY constant value., (*24)

Global Seo Pattern

You can use global seo pattern to all model istance by set is_global parameter to to 1 for model seoContent. Just create form in view like this:, (*25)

<?php $form = \yii\widgets\ActiveForm::begin(); ?>
<?= $form->field($model, 'seoTitle')->textInput(); ?>
<?= $form->field($model, 'seoKeywords')->textInput(); ?>
<?= $form->field($model, 'seoDescription')->textarea(); ?>
<?php \yii\widgets\ActiveForm::end(); ?>

And process it at you controller like this:, (*26)

/* @var $model Page */
$model = new Page();

/* @var $seo SeoContent */
$seo = $model->getSeoContentModel();
if ($seo->load(Yii::$app->request->post())) {
    $seo->is_global = 1;
    $seo->save();
}

Sql Caching

For enable sql queries caching set enableSqlQueryCache parameter at behavior config to to true. Also you can set cache duration by sqlQueryCacheDuration parameter. Example:, (*27)

/**
 * @inheritdoc
 */
public function behaviors() {
    return [
        'seo' => [
            'class' => SeoBehavior::className(),
            'enableSqlQueryCache' => true,
            'sqlQueryCacheDuration' => 24*60*60*30*12, // 1 year
        ]
    ];
}

License

The MIT License (MIT). Please see License File for more information., (*28)

The Versions

02/06 2018

dev-master

9999999-dev

Seo behavior for Yii2 models and meta tags helper with patterns using possibility

  Sources   Download

MIT

The Requires

 

by Roman Agilov
by Igor Veremsky

yii2 behavior seo patterns romi45

02/06 2018

1.0.6

1.0.6.0

Seo behavior for Yii2 models and meta tags helper with patterns using possibility

  Sources   Download

MIT

The Requires

 

by Roman Agilov
by Igor Veremsky

yii2 behavior seo patterns romi45

11/05 2018

1.0.5

1.0.5.0

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 behavior seo romi45

08/05 2018

dev-sql-queries-cache

dev-sql-queries-cache

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 behavior seo romi45

12/03 2018

1.0.4

1.0.4.0

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 behavior seo romi45

22/02 2018

1.0.3

1.0.3.0

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 behavior seo romi45

22/02 2018

dev-pattern-for-seo-meta-tag

dev-pattern-for-seo-meta-tag

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 behavior seo romi45

19/02 2016

1.0.2

1.0.2.0

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 behavior seo romi45

19/02 2016

1.0.1

1.0.1.0

Seo behaviour for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 seo romi45 behaiviour

19/02 2016

1.0.0

1.0.0.0

Seo behaiviour for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 seo romi45 behaiviour

19/02 2016

0.0.1

0.0.1.0

Seo behaiviour for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

by Roman Agilov

yii2 seo romi45 behaiviour