sbs/yii2-transliterator-helper
Composer 安装命令:
composer require sbs/yii2-transliterator-helper
包简介
The transliterator helper for the Yii 2 framework
README 文档
README
Transliterator Helper transliterates UTF-8 encoded text to US-ASCII.
Installation
The preferred way to install this extension is through composer.
Either run
composer require sbs/yii2-transliterator-helper
or add
"sbs/yii2-transliterator-helper": "*"
to the require section of your application's composer.json file.
Usage
Pass to the method process() the UTF-8 encoded string you wish to transliterate:
use sbs\helpers\TransliteratorHelper;
// will echo AAAAAAAECEEEEIIIIDNOOOOOUUUUYssaaaaaaaeceeeeiiiidnooooouuuuyy
TransliteratorHelper::process('ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöùúûüýÿ', 'en'));
You can use it as application behavior:
use sbs\behaviors\SlugBehavior;
//...
public function behaviors()
{
return [
//...
[
'class' => SlugBehavior::class,
'attribute' => 'title',
'slugAttribute' => 'slug',
],
];
}
Since version 0.3 you can use SlugInput widget:
Configurations:
You need a registration controller in your main config file in section controllerMap:
use sbs\controllers\TransliterationController; //... 'controllerMap' => [ 'transliteration' => [ 'class' => TransliterationController::class, 'lowercase' => false //provides transliteration to lower case, true by default. ] ], //...
Like a widget:
use sbs\widgets\SlugInput; echo SlugInput::widget([ 'name' => 'News[slug]', 'sourceName' => 'News[title]' ]);
Like an ActiveForm widget:
use sbs\widgets\SlugInput; echo $form->field($model, 'slug')->widget(SlugInput::class, [ 'sourceAttribute' => 'title' ]);
That's all. Enjoy.
统计信息
- 总下载量: 677
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-01-01