andrewdanilov/yii2-city-switch

Widget for switching city on site

1.0.0 2019-04-16 12:37 UTC

This package is auto-updated.

Last update: 2024-04-16 21:56:25 UTC


README

Warning: component is under cunstruction. Do not use it.

Component for switching city on site. You can display a personificated info associated to selected city (for example address or phone in that city). It uses cookies, so pay attention to that fact, that by changing city you do not change page web address.

Installation

The preferred way to install this extension is through composer.

Either run

composer require andrewdanilov/yii2-city-switch "~1.0.0"

or add

"andrewdanilov/yii2-city-switch": "~1.0.0"

to the require section of your composer.json file.

Then you need to run migrations, to create cities table

yii migrate --migrationPath=@andrewdanilov/cityswitch/migrations

Usage

Add to bootstrap section in main config of your backend:

return [
	...
	'bootstrap' => [
		...
		'cityswitch' => [
			'class' => andrewdanilov\cityswitch\backend\Bootstrap,
			// data params which you want to be associated with each city
			// in addition to city alias (`city`) and city name (`city_name`)
			'dataParams' => [
				'address' => 'City address',
				'phone' => 'City phone',
				'coords' => 'City address coordinates',
			],
			// defining access to module
			'access' => ['admin'],
		],
	],
];

This needs to edit cities data in backend of your site. Backend url would be:

admin/cityswitch

To display city switcher menu, use:

<?= \andrewdanilov\cityswitch\CitySwitchMenu::widget() ?>

To display current city value:

<?= \andrewdanilov\cityswitch\CitySwitchValue::widget(['param' => 'phone']) ?>