PHPackages                             asinfotrack/yii2-toolbox - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. asinfotrack/yii2-toolbox

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

asinfotrack/yii2-toolbox
========================

Yii2-Toolbox is a collection of useful helpers, widgets etc. extending the basic functionality of Yii2

1.0.6(5y ago)1230.5k7[2 PRs](https://github.com/asinfotrack/yii2-toolbox/pulls)5MITPHPPHP &gt;=7.1.0

Since Feb 16Pushed 4y ago6 watchersCompare

[ Source](https://github.com/asinfotrack/yii2-toolbox)[ Packagist](https://packagist.org/packages/asinfotrack/yii2-toolbox)[ RSS](/packages/asinfotrack-yii2-toolbox/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (23)Used By (5)

yii2-toolbox
============

[](#yii2-toolbox)

Yii2-Toolbox is a collection of useful helpers, widgets etc. extending the basic functionality of Yii2

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

```
"asinfotrack/yii2-toolbox": "~1.0.1"

```

Changelog
---------

[](#changelog)

[Learn about the latest improvements](CHANGELOG.md).

Contents
--------

[](#contents)

### Components

[](#components)

###### MemoryUrlManager

[](#memoryurlmanager)

This URL manager implements memory-functionality for urls. This enables for example to keep the state (sorting, filtering and paging) of a GridView across requests. The default configuration saves this data in the session variable and appends the params to the links.

The usage is very easy. Simply set this class as the url manager in your Yii-config and specify the additional attributes according to the example below and the documentation within the class.

Example of a config:

```
// ...
'urlManager'=>[
	'class'=>'\asinfotrack\yii2\toolbox\components\MemoryUrlManager',

	'memoryMap'=>[

		//the controller
		'mycontroller'=>[
			//the action
			'myindexaction'=>[
				//regex rules...if a param matches a rule it will be memorized
				'/^SearchForm/',
				//if a rule is specified like this, the regex is only enabled if the callback returns true
				'page'=>function() {
					return rand(0,1) == 1;
				},
			],
		],

		//modules work the same, except they have one level more
		'mymodule'=>[
			'mymodulecontroller'=>[
				//the action
				'mymoduleaction'=>[
					//regex rules...if a param matches a rule it will be memorized
					'/^MyForm/',
				],
			],
		],

	],
],
// ...
```

Each entry in the `memoryMap` can be a string representing a regex to match params to save. You can optionally use the regex-rule as key and a callback returning a boolean as the value. In this case the rule is only active when the callback returns true

###### ImageResponseFormatter

[](#imageresponseformatter)

Response formatter for images. You need to add the formatter to the config as follows:

```
'response' => [
	// ...
	'formatters'=>[
		'img_jpg'=>[
			'class'=>'asinfotrack\yii2\toolbox\components\ImageResponseFormatter',
			'extension'=>'jpg',
		],
		'img_png'=>[
			'class'=>'asinfotrack\yii2\toolbox\components\ImageResponseFormatter',
			'extension'=>'png',
		],
		'img_gif'=>[
			'class'=>'asinfotrack\yii2\toolbox\components\ImageResponseFormatter',
			'extension'=>'gif',
		],
	],
	// ...
],
```

After that you can use it to output images via actions easily:

```
public function actionAvatar()
{
	Yii::$app->response->format = 'img_png';
	return file_get_contents($pathToMyImage);
}
```

###### PdfResponseFormatter

[](#pdfresponseformatter)

Additional response formatter for handling PDF-requests. You need to add the formatter to the config like this:

```
'response' => [
	// ...
	'formatters'=>[
		'pdf'=>'asinfotrack\yii2\toolbox\components\PdfResponseFormatter',
		'pdf_download'=>[
			'class'=>'asinfotrack\yii2\toolbox\components\PdfResponseFormatter',
			'forceDownload'=>true,
		],
	],
	// ...
],
```

After that you can use it to output PDFs via actions easily:

```
public function actionPdf()
{
	//create pdf with some library (eg FPDF)
	$pdf = new FPDF();
	// ...

	$response = Yii::$app->response;
	$response->data = $pdf->Output();
	$response->format = 'pdf';
}
```

###### User

[](#user)

Extends `\yii\web\User` with the ability to check multiple rights at once (canAll, canAny, canOne).

###### ProgressiveImageGd and ProgressiveImageImagick

[](#progressiveimagegd-and-progressiveimageimagick)

Both classes extend the image drivers of `yurkinx/yii2-image` to enable progressive encoding of jpg-files. To use it, simply call the factory-class `asinfotrack\yii2\toolbox\helpers\ImageFactory::createInstance($path, $driver=self::DRIVER_GD)`to get an instance and proceed working. Make sure either GD- or Imagick-Library is enabled.

### Widgets

[](#widgets)

###### Button

[](#button)

The button-widget extends the one provided by yii2. It adds functionality to specify an icon. The Icons depend on font-awesome and hence require the yii2-extension `rmrevin/yii2-fontawesome`

###### AjaxToggleButton

[](#ajaxtogglebutton)

An ajax button to toggle boolean values (1, 0). Together with `AjaxAttributeAction` this makes it very easy to toggle boolean flags. The widget-attribute `booleanAttribute` is used only for reading out values. Therefore you have to respecify this in the controller-action (step 2 below).

Example of usage together with `AjaxAttributeAction`:

```
