PHP code example of asinfotrack / yii2-toolbox

1. Go to this page and download the library: Download asinfotrack/yii2-toolbox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

asinfotrack / yii2-toolbox example snippets


// ...
'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/',
				],
			],
		],

	],
],
// ...

'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',
		],
	],
	// ...
],

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

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

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

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

<?= AjaxToggleButton::widget([
	'model'=>$model,
	'booleanAttribute'=>'is_archived',
	'action'=>'toggle-archived',
	'options'=>['class'=>'btn-primary btn-xs'],
]);

public function actions()
{
	return [
		'toggle-archived'=>[
			'class'=>AjaxAttributeAction::className(),
			'targetClass'=>User::className(),
			'targetAttribute'=>'is_archived',
		],
	];
}

<?= FlashMessages::widget() 

<?= FlashMessages::widget([
    'loadFlashesCallback'=>function() {
        return ['info'=>'Hello', 'danger'=>'World!'];
    },
]) 

 Panel::begin([
	'heading'=>Html::tag('h3', 'Welcome!'),
	'footer'=>function() {
		return Yii::$app->formatter->asDatetime(time());
	},
]); 

public function actions()
{
    return [
        // ...
        [
            'class'=>'asinfotrack\yii2\toolbox\actions\DebugAction',
            'view'=>'//site/debugging',
        ]
        // ...
    ];
}

<?= $content 

public function rules()
{
    return [
        // ...
        [['phonePrivate','phoneWork','mobile'], SelectiveRequiredValidator::className(), 'errorAttribute'=>'phonePrivate'],
        // ...
    ];
}

'modules'=>[
	// ...
	'gii'=>[
		'class'=>'yii\gii\Module',
		'generators'=>[
			'model'=>[
				'class'=>'asinfotrack\yii2\toolbox\gii\model\Generator',
				'templates'=>[
					'asiToolboxModel'=>'@vendor/asinfotrack/yii2-toolbox/gii/model/default',
				],
			],
			'crud'=>[
				'class'=>'asinfotrack\yii2\toolbox\gii\crud\Generator',
				'templates'=>[
					'asiToolboxCrud'=>'@vendor/asinfotrack/yii2-toolbox/gii/crud/default',				
				],
			],
		],
	],
	// ...
],