Yii2 的 SEO 模块

2.0.3 2016-02-29 08:13 UTC

This package is not auto-updated.

Last update: 2024-09-28 16:03:44 UTC


README

安装

安装此扩展的最佳方式是通过 composer

运行以下命令之一:

php composer.phar require infoweb-internet-solutions/yii2-cms-seo "*"

或将其添加到你的 composer.json 文件的 require 部分:

"infoweb-internet-solutions/yii2-cms-seo": "*"

用法

扩展安装后,只需按照以下方式修改你的应用程序配置:

以下是你后端配置的方式

'modules' => [
    ...
    'seo' => [
        'class' => 'infoweb\seo\Module',
    ],
],

导入翻译并使用类别 'infoweb/seo'

yii i18n/import @infoweb/seo/messages

要使用该模块,执行 yii 迁移

yii migrate/up --migrationPath=@vendor/infoweb-internet-solutions/yii2-cms-seo/migrations

行为

要使用 SeoBehavior,将以下代码插入你的 ActiveRecord 类中

use infoweb\seo\behaviors\SeoBehavior;

public function behaviors()
{
    return [
        'seo' => [
            'class' => SeoBehavior::className(),
            'titleAttribute' => 'title',
        ],
    ];
}

将此代码添加到你的视图中

 // Initialize the tabs
$tabs = [
    ...
    [
        'label' => 'SEO',
        'content' => $this->render('@infoweb/seo/views/behaviors/seo/_seo_tab', ['model' => $model, 'form' => $form]),
    ],
];

配置

以下列出了所有可用的配置选项及其默认值。

allowContentDuplication (类型: boolean, 默认: true)

如果此选项设置为 true,则会在所有可翻译属性上激活 duplicateable jQuery 插件。