mmelcor/yii2-imagehandler

A component to handle retriving multi-lingual images from an image repository.

Installs: 38

Dependents: 1

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0

Type:yii2-extension

0.6 2017-06-27 18:34 UTC

This package is not auto-updated.

Last update: 2024-04-27 17:03:55 UTC


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.