cetver/yii2-language-url-manager 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

cetver/yii2-language-url-manager

最新稳定版本:1.0.2

Composer 安装命令:

composer require cetver/yii2-language-url-manager

包简介

Parses and creates URLs containing languages for the Yii framework 2.0

README 文档

README

Build Status Coverage Status

Parses and creates URLs containing languages

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist cetver/yii2-language-url-manager

or add

"cetver/yii2-language-url-manager": "^1.0"

to the require section of your composer.json file.

Usage

Update the web-application configuration file

return [
    'components' => [
        'urlManager' => [
            'class' => 'cetver\LanguageUrlManager\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            /*
             * The list of available languages.
             */
            'languages' => ['en', 'ru'],
            /*
            or
            'languages' => function () {
                return \app\models\Language::find()->select('code')->column();
            },
            */
            /*
             * - true: processes the URL like "en.example.com"
             * - false: processes the URL like "example.com/en"
             * NOTE: If this property set to true, the domain containing a language, must be the first on the left side,
             * for example:
             * - en.it.example.com - is valid
             * - it.en.example.com - is invalid
             */
            'existsLanguageSubdomain' => false,
            /*
             * The regular expression patterns list, applied to path info, if there are matches, the request,
             * containing a language, will not be processed.
             * For performance reasons, the blacklist does not applied for URL creation (Take a look at an example).
             * @see \yii\web\Request::getPathInfo()
             * An example:
             * ```php
             * [
             *     '/^api.*$/'
             * ]
             * ```
             * - Requesting the blacklisted URL
             *   - $existsLanguageSubdomain = true
             *     - en.example.com/api (404 Not Found)
             *     - en.example.com/api/create (404 Not Found)
             *   - $existsLanguageSubdomain = false
             *     - example.com/en/api (404 Not Found)
             *     - example.com/en/api/create (404 Not Found)
             * - Creating the blacklisted URL
             *   - echo \yii\helpers\Html::a('API', ['api/index', Yii::$app->urlManager->queryParam => null]);
             */
            'blacklist' => [],
            /*
             * The query parameter name that contains a language.
             */
            'queryParam' => 'language'
        ],
    ]
];

Tests

Run the following commands

composer create-project --prefer-source cetver/yii2-language-url-manager
cd yii2-language-url-manager
vendor/bin/codecept run unit

For I18N support, take a look at

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2017-07-19