laco-agency/seo-behavior
Composer 安装命令:
composer require laco-agency/seo-behavior
包简介
Seo behavior for Yii2 models and meta tags helper
关键字:
README 文档
README
Seo behavior for Yii2 models and meta tags helper
Installing
composer require --prefer-dist laco-agency/seo-behavior
or add
"laco-agency/seo-behavior": "*"
to the require section of your composer.json.
Usage
Model:
use laco/seo/SeoModelBehavior;
public function behaviors() { return [ [ 'class' => SeoModelBehavior::className(), 'descriptionFromAttribute' => 'teaser', 'metaImageAttribute' => 'image_preview' ] ] }
Controller:
use laco/seo/SeoControllerBehavior;
Attach behavior:
public function behaviors() { return [ SeoControllerBehavior::className() ]; }
In case when parent controller already has behaviors, you can attach SeoControllerBehavior like this:
public function behaviors() { $behaviors = [ 'access' => [ 'class' => AccessControl::className(), 'rules' => [] ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [] ] ]; return array_merge(parent::behaviors(), $behaviors); }
Or like this:
public function init() { $this->attachBehavior('seo', SeoControllerBehavior::className()); }
Action:
In the action use the method $this->setMetaTags($model) and pass $model as parameter;
public function view($slug) { $model = Material::findOne(['slug' => $slug])); $this->setMetaTags($model); }
Or use an array in this format instead of model:
[
'metaTitle' => 'Custom meta title',
'metaDescription' => 'Custom description',
'metaImage' => 'Custom meta image'
]
统计信息
- 总下载量: 26
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-07-06