Menus

Thursday 13 August 2015

Yii2 more useful programming tips.



Returns the values of a specified column in an array.

getColumn() public method
Returns the values of a specified column in an array.
The input array should be multidimensional or an array of objects.
For example,
$array = [
    ['id' => '123', 'data' => 'abc'],
    ['id' => '345', 'data' => 'def'],
];
$result = ArrayHelper::getColumn($array, 'id');
// the result is: ['123', '345']

// using anonymous function
$result = ArrayHelper::getColumn($array, function ($element) {
    return $element['id'];
});







Automatic Logout after 30 minutes of inactive



$authTimeout public property
The number of seconds in which the user will be logged out automatically if he remains inactive. If this property is not set, the user will be logged out after the current session expires (c.f. yii\web\Session::$timeout). 


Add your config/web.php file


'user' => [
            'identityClass' => 'app\models\User',
            //'enableAutoLogin' => true,
            'enableSession' => true,
            'authTimeout' => 60,
        ],











No comments:

Post a Comment