gregory-coolich/

yii2-seotools

组件和模块,用于管理页面独特的SEO标题、描述、h1标题和与页面相关联的独特文本

安装: 5

依赖者: 0

建议者: 0

安全: 0

类型:yii2-extension

dev-master 2024-07-13 17:55 UTC

This package is not auto-updated.

Last update: 2024-09-22 17:13:43 UTC


README

如果您需要设置与页面关联的独特SEO标题和描述,这个扩展就是您所需要的,您还可以使用wysiwyg工具添加加粗文本和链接,以独特内容提高页面的SEO。

使用模块设置这些字段以管理所有这些功能。

内部使用md5哈希来生成一个独特的ID,ID由(主机 + 路径)组成,用于标识页面、yii缓存系统和标签依赖关系,以提高速度

安装

安装此扩展的首选方式是通过 composer

运行以下命令

php composer.phar require --prefer-dist ryhor123/yii2-seotools "*"

或者

"ryhor123/yii2-seotools": "*"

将以下内容添加到您的 composer.json 文件的require部分。

迁移

在终端中运行以下命令进行数据库迁移

Linux/Unix

yii migrate/up --migrationPath=@vendor/ryhor123/yii2-seotools/migrations

Windows

yii.bat migrate/up --migrationPath=@vendor/ryhor123/yii2-seotools/migrations

配置

开启seotool组件的简单示例。

'components' => [
        'seotools' => [
            'class' => 'ryhor123\seotools\Component',
        ],
    ],

开启seotools模块

简单示例

    'modules' => [
        'seotools' => [
            'class' => 'ryhor123\seotools\Module',
            'roles' => ['@'], // For setting access levels to the seotools interface.
        ]
    ],

使用

安装扩展后,您只需在代码中简单使用它即可

 // @param bool $setCanonical true, try to create a canonical url and og url, action needs to have params
 // @param bool $checkDb try to get from DB params, true: try to get info from DB if it doesn't find save a new field
 // associated to current host + '/' + path, false: it just set the params give in the call. The db params has priority
 // over the call function params. It does a merge
$setCanonical = false;
$checkDb = true;
Yii::$app->seotools->setMeta(['title' => \Yii::t('title','A good title for this page')], $setCanonical, $checkDb);

通过调用无效缓存来保存记录

\yii\caching\TagDependency::invalidate(Yii::$app->cache, ryhor123\seotools\Component::CACHE_TAG);

URLs

seotools管理模块的URL

/seotools/manage
/seotools/manage/create