if($this->created_at){
$date = new \DateTime($this->created_at);
$start = $date->getTimestamp();
//константа SECONDS_IN_DAY содержит в себе 86400 и объявлена заранее
$query->andFilterWhere(['between', 'created_at', $start, $start + self::SECONDS_IN_DAY]);
}
if($models->validate()) {
\Yii::$app->session->setFlash('success', 'Форма отправлена 1');
return $this->refresh();
} else {
\Yii::$app->session->setFlash('error', 'Форма не отправлена 1');
}
<?php
$usa = [
['Los-Angeles', 'Californiy', 3792621],
['San-Diego', 'Californiy', 1307402],
['San-Xose', 'Californiy', 945942],
['Dallas', 'Texas', 1197816],
['San-Antonio', 'Texas', 1327407],
['Xiqston', 'Texas', 2100263],
['Feladelfiy', 'Pensilvaniy', 1526006],
['Feniks', 'Arizona', 1445632],
['Chicago', 'Ilynois', 2695598]
];
$summary = [];
foreach ($usa as $item){
$state = $item[1];
$peoples = $item[2];
if(array_key_exists($state, $summary)){
$summary[$state] += $peoples;
} else {
$summary[$state] = $peoples;
}
}
print_r($summary);
<?php
namespace common\behaviors;
use yii\base\Behavior;
use yii\base\InvalidConfigException;
use yii\db\ActiveRecord;
use yii\base\Event;
/**
* Class DateFormatTranslator
* @package common\behaviors
*/
class DateFormatTranslator extends Behavior
{
public $machineFormat = 'php:Y-m-d';
public $humanFormat = 'php:d.m.Y';
public $attributes;
/**
* @throws InvalidConfigException
*/
public function init()
{
if(empty($this->attributes)){
throw new InvalidConfigException('attributes can not be empty');
}
return parent::init();
}
/**
* @return array
*/
public function events()
{
return [
ActiveRecord::EVENT_BEFORE_UPDATE => 'toMachineFormat',
ActiveRecord::EVENT_BEFORE_INSERT => 'toMachineFormat',
ActiveRecord::EVENT_AFTER_INSERT => 'toHumanFormat',
ActiveRecord::EVENT_AFTER_FIND => 'toHumanFormat',
];
}
/**
* @param $event Event
* @var $owner ActiveRecord
*/
public function toHumanFormat(Event $event){
$formatter = \Yii::$app->formatter;
$owner = $event->sender;
foreach ($this->attributes as $attribute){
if(!empty($owner->$attribute)){
$owner->$attribute = $formatter->asDate($owner->$attribute, $this->humanFormat);
}
}
}
/**
* @param Event $event
*/
public function toMachineFormat(Event $event){
$formatter = \Yii::$app->formatter;
$owner = $event->sender;
foreach ($this->attributes as $attribute){
if(!empty($owner->$attribute)) {
$owner->$attribute = $formatter->asDate($owner->$attribute, $this->machineFormat);
}
}
}
}
AppointmentForm[email]
'user' => [
'controllerMap' => [
'recovery' => [
'class' => 'dektrium\user\controllers\RecoveryController',
'layout' => '@backend/views/layouts/main-login'
],
'security' => [
'class' => 'dektrium\user\controllers\SecurityController',
'layout' => '@backend/views/layouts/main-login'
]
],
'modelMap' => [
'LoginForm' => 'backend\models\LoginForm',
],
]