mmelcor/yii2-imagehandler
Composer 安装命令:
composer require mmelcor/yii2-imagehandler
包简介
A component to handle retriving multi-lingual images from an image repository.
README 文档
README
Yii2 Multi-language Image Handler
An extension designed to retrive images from an online Repository based on the currently selected application language.
Installation
The preferred method of installation is via composer.
Either run
php composer.phar require --prefer-dist mmelcor/yii2-imagehandler "*"
or add
"mmelcor\yii2-imagehander": "*"
to the require section of your composer.json file.
Usage
Once installed, use it in your application by adding the following to your components section in common\config\main.php (advanced) or config\web.php (basic template) :
'components' => [ '[other components]', 'imageHandler' => [ 'class' => 'mmelcor\imagehandler', 'hostUrl' => '[your image repo base url]', 'siteFolder' => '[base folder]', 'defaultLang' => '[Language that will have all images]', ], ],
In your controller either add the component to your init() by delcaring a protected variable and passing it as a parameter:
protected $iHandler;
public function init() {
$this->iHandler = Yii::$app->imageHandler;
}
$this->parameters = [
'iHandler' => $this->iHandler,
]:
or pass it to your views in the view action:
$iHandler = Yii::$app->imageHandler;
return $this->render('view', [
'iHandler' => $iHandler,
]);
to call the specific image place the following in your view.
<img src="<?= $iHandler->getImage('/path/to/img') ?>" class="[classes]" alt="[image description]" />
This component works best with oorrwullie\yii2-babelfishfood.
统计信息
- 总下载量: 38
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-02-15