本文整理汇总了PHP中app\models\Event::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Event::validate方法的具体用法?PHP Event::validate怎么用?PHP Event::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Event
的用法示例。
在下文中一共展示了Event::validate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testValidateCorrect
public function testValidateCorrect()
{
$model = new Event(['type' => 'Type', 'name' => 'Name', 'event' => 'Event', 'title' => 'Title']);
$this->specify('event wrong', function () use($model) {
expect('model should not validate', $model->validate())->true();
});
}
示例2: actionEvents
/**
* Добавление события
* @return string
*/
public function actionEvents()
{
if (Yii::$app->getRequest()->getQueryParam('user')) {
$start_day = strtotime('now 00:00:00', time() + 7 * 60 * 60);
$user = MarkUser::findOne(Yii::$app->getRequest()->getQueryParam('user'));
if (!$user) {
return 'Доступ запрещен!';
}
if (Yii::$app->getRequest()->getQueryParam('text') && Yii::$app->getRequest()->getQueryParam('cat')) {
if (Categories::find()->where("name like '" . trim(Yii::$app->getRequest()->getQueryParam('cat') . "'"))->one()) {
$cat_id = Categories::find()->where(['name' => Yii::$app->getRequest()->getQueryParam('cat')])->one()->id;
//$item->cat_id = Categories::find()->where("name like '".trim(Yii::$app->getRequest()->getQueryParam('cat')."'"))->one()->id;
} else {
return "Категория!";
}
$act = new DiaryActs();
$act->model_id = 10;
$act->user_id = $user->id;
//return var_dump($act);
if ($act->save(false)) {
$event = new Event();
$event->act_id = $act->id;
$event->cat_id = $cat_id;
if (Yii::$app->getRequest()->getQueryParam('old_data_ev')) {
$event->old_data = Yii::$app->getRequest()->getQueryParam('old_data_ev');
}
$event->user_id = $act->user_id;
$event->text = Yii::$app->getRequest()->getQueryParam('text');
if (!$event->validate()) {
return 'Данные введены некорректно';
} else {
if ($event->save()) {
return "<p>Событие сохранено!</p>";
} else {
return 'Ошибка сохранения';
}
}
}
}
$today_event_acts = implode(',', ArrayHelper::map(DiaryActs::find()->where("time > {$start_day} and user_id = " . $user->id . " and model_id = 10")->all(), 'id', 'id'));
$today_event = [];
//return var_dump($today_event_acts);
if ($today_event_acts) {
$today_event = Event::find()->where("act_id IN (" . $today_event_acts . ")")->orderBy('id DESC')->andWhere(["old_data" => 0])->all();
}
//return var_dump($today_event);
return $this->renderPartial('add_event', ['user' => $user, 'today_event' => $today_event]);
}
}