承接 v0lume/yii2-meta-tags 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

v0lume/yii2-meta-tags

最新稳定版本:v1.2.3

Composer 安装命令:

composer require v0lume/yii2-meta-tags

包简介

DB based model meta data for SEO

README 文档

README

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.

统计信息

  • 总下载量: 4.14k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 19
  • Watchers: 2
  • Forks: 7
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-12