yii2-meta-tags

storing meta-tags for model in db (yii2)

  • 所有者: v0lume/yii2-meta-tags
  • 平台:
  • 許可證: MIT License
  • 分類:
  • 主題:
  • 喜歡:
    0
      比較:

Github星跟蹤圖

yii2-meta-tags

DB based model meta data for SEO

screenshot

Installation

The preferred way to install this extension is through composer.

Either run

composer.phar require --prefer-dist v0lume/yii2-meta-tags "*"

or add

"v0lume/yii2-meta-tags": "*"

to the require section of your composer.json file.

Usage

Add MetaTagBehavior to your model, and configure it.


public function behaviors()
{
    return [
        'MetaTag' => [
            'class' => MetaTagBehavior::className(),
        ],
    ];
}

Add MetaTags somewhere in you application, for example in editing form.

echo MetaTags::widget([
    'model' => $model,
    'form' => $form
]);

Done! Now, you can get meta data of your current model:

echo $model->getBehavior('MetaTag')->title;
echo $model->getBehavior('MetaTag')->keywords;
echo $model->getBehavior('MetaTag')->description;

Or, by manually find model:

use v0lume\yii2\metaTags\model\MetaTag;

...

$meta_tag = MetaTag::findOne([
    'model_id' => $id,
    'model'  => (new \ReflectionClass($model))->getShortName()
]);

...

echo $meta_tag->title;
echo $meta_tag->keywords;
echo $meta_tag->description;

Auto registration meta tags

You can use MetaTagsComponent to perform auto registration meta tags

Configure MetaTagsComponent in main.php config:


...
'components' => [
    ...
    'metaTags' => [
        'class' => 'v0lume\yii2\metaTags\MetaTagsComponent',
        'generateCsrf' => false,
        'generateOg' => true,
    ],
    ...
],
...
    

And then, in your layouts or views or controller action

$model = \common\models\Page::findOne(['url' => '/']);

Yii::$app->metaTags->register($model);

If passed $model was attached MetaTagBehavior, component will register meta tags for that model. If MetaTagBehavior wasn't attached or model not passed, and generateCsrf is set to true, component will generate only csrf meta tags.

主要指標

概覽
名稱與所有者v0lume/yii2-meta-tags
主編程語言PHP
編程語言PHP (語言數: 1)
平台
許可證MIT License
所有者活动
創建於2015-03-11 11:43:41
推送於2017-07-18 22:39:11
最后一次提交2017-07-12 12:16:59
發布數6
最新版本名稱v1.2.3 (發布於 )
第一版名稱v1.0 (發布於 )
用户参与
星數18
關注者數2
派生數7
提交數12
已啟用問題?
問題數5
打開的問題數2
拉請求數1
打開的拉請求數0
關閉的拉請求數1
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?