common/helpers.php
<?php
/*
* This file is part of the HomeFinanceV2 project.
*
* (c) Rafalsky.com <http://github.com/Rafalsky/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* Yii2 Shortcuts
* @author Eugene Terentev <eugene@terentev.net>
* -----
* This file is just an example and a place where you can add your own shortcuts,
* it doesn't pretend to be a full list of available possibilities
* -----
*/
/**
* @return int|string
*/
function getMyId()
{
return Yii::$app->user->getId();
}
/**
* @param string $view
* @param array $params
* @return string
*/
function render($view, $params = [])
{
return Yii::$app->controller->render($view, $params);
}
/**
* @param $url
* @param int $statusCode
* @return \yii\web\Response
*/
function redirect($url, $statusCode = 302)
{
return Yii::$app->controller->redirect($url, $statusCode);
}
/**
* @param $form \yii\widgets\ActiveForm
* @param $model
* @param $attribute
* @param array $inputOptions
* @param array $fieldOptions
* @return string
*/
function activeTextinput($form, $model, $attribute, $inputOptions = [], $fieldOptions = [])
{
return $form->field($model, $attribute, $fieldOptions)->textInput($inputOptions);
}
/**
* @param string $key
* @param mixed $default
* @return mixed
*/
function env($key, $default = false)
{
$value = getenv($key);
if ($value === false) {
return $default;
}
switch (strtolower($value)) {
case 'true':
case '(true)':
return true;
case 'false':
case '(false)':
return false;
}
return $value;
}