2017 © Pedro Peláez
 

yii2-extension seo-behavior

Seo behavior for Yii2 models and meta tags helper

image

laco-agency/seo-behavior

Seo behavior for Yii2 models and meta tags helper

  • Wednesday, August 23, 2017
  • by laco-agency
  • Repository
  • 2 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

SEO Behavior

Seo behavior for Yii2 models and meta tags helper, (*1)

Installing

composer require --prefer-dist laco-agency/seo-behavior

or add, (*2)

"laco-agency/seo-behavior": "*"

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

Usage

Model:, (*4)

use laco/seo/SeoModelBehavior;
public function behaviors()
{
    return [
        [
            'class' => SeoModelBehavior::className(),
            'descriptionFromAttribute' => 'teaser',
            'metaImageAttribute' => 'image_preview'
       ]
   ]
}

Controller:, (*5)

use laco/seo/SeoControllerBehavior;

Attach behavior:, (*6)

public function behaviors()
{
    return [
        SeoControllerBehavior::className()
   ];
}

In case when parent controller already has behaviors, you can attach SeoControllerBehavior like this:, (*7)

public function behaviors()
{
    $behaviors = [
        'access' => [
            'class' => AccessControl::className(),
            'rules' => []
        ],
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => []
        ]
    ];
    return array_merge(parent::behaviors(), $behaviors);
}

Or like this:, (*8)

public function init()
{
    $this->attachBehavior('seo', SeoControllerBehavior::className());
}

Action:, (*9)

In the action use the method $this->setMetaTags($model) and pass $model as parameter;, (*10)

public function view($slug)
{
    $model = Material::findOne(['slug' => $slug]));
    $this->setMetaTags($model);
}

Or use an array in this format instead of model:, (*11)

[
    'metaTitle' => 'Custom meta title',
    'metaDescription' => 'Custom description',
    'metaImage' => 'Custom meta image'
]

The Versions

23/08 2017

dev-master

9999999-dev https://github.com/laco-agency/seo-behavior

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

yii2 behavior seo meta tags

23/08 2017

0.3

0.3.0.0 https://github.com/laco-agency/seo-behavior

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

yii2 behavior seo meta tags

06/07 2017

0.2

0.2.0.0 https://github.com/laco-agency/seo-behavior

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

yii2 behavior seo meta tags

06/07 2017

0.1

0.1.0.0 https://github.com/laco-agency/seo-behavior

Seo behavior for Yii2 models and meta tags helper

  Sources   Download

MIT

The Requires

 

yii2 behavior seo meta tags