定制 shershennm/yii2-seo 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

shershennm/yii2-seo

最新稳定版本:3.1.1

Composer 安装命令:

composer require shershennm/yii2-seo

包简介

Yii2 extension for simple generating keywords and description

README 文档

README

Yii2 module for easy creating meta tags

Installation

composer require shershennm/yii2-seo:"^3.0"

Usage

In config file:

<?php
...
'bootstrap' => ['log', 'seo'], // add seo component to application bootstrap
...
'components' => [
	...
    'seo'         => [
        'class' => 'shershennm\seo\Seo',
        'controllerMapping' => [
            'app\controllers' => 'app\seo\controllers', // controller namespace for seo module
        ],

    ],
]

Seo controller example:

<?php

namespace app\seo\controllers;

use Yii;
use shershennm\seo\SeoController;

class SiteController extends SeoController
{
    /**
    * $viewParams array View Params from actionIndex in SiteController
    **/
    public function actionIndex($viewParams)
    {
        $this->title = 'Hello world!';

        $this->registerMetaTag(['name' => 'description', 'content' => 'Cool page!']);
        $this->registerLinkTag([['rel' => 'next', 'href' => 'https://my-cool-page.lh/article/2']]);

        return [
            ['name' => 'keywords', 'content' => $this->getKeywords()], // params for View::registerMetaTag() function
            ['name' => 'description', 'content' => 'Cool page!'],
        ];
    }

    private function getKeywords()
    {
        // $this->controller instance of current controller
        return implode($this->controller->words, ', ');
    }

	....

You can use OnePagSeoController for controller which have index action for different routes. Example:

<?php

namespace frontend\seo\controllers;

use shershennm\seo\OnePageSeoController;

class SiteController extends OnePageSeoController
{
    protected $titles = [
        'site/info' => 'Site Info',
    ];
    protected $wildcardTitles = [
        '/site\/history/' => 'Site History',
    ];
}

Route of $titles will be applied only to pages with same route. $wildcardTitles use regular expression as route.

统计信息

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

GitHub 信息

  • Stars: 5
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-10-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固