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
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
- https://github.com/cetver/yii2-languages-dispatcher - Sets the web-application language
- https://github.com/cetver/yii2-language-url-manager - Parses and creates URLs containing languages
- https://github.com/cetver/yii2-language-selector - Provides the configuration for the language selector
- https://github.com/creocoder/yii2-translateable - The translatable behavior (Active Record)
统计信息
- 总下载量: 111.92k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-07-19