本文整理汇总了PHP中app\Message::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::validate方法的具体用法?PHP Message::validate怎么用?PHP Message::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Message
的用法示例。
在下文中一共展示了Message::validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createMessage
protected function createMessage($from, $msg)
{
echo sprintf('User %d sending message "%s" to user %d' . "\n", $from->userId, $msg->message, $msg->userTo);
$dialog = new Dialog();
$dialog->from = $from->userId;
$dialog->to = $msg->userTo;
if ($dialog->validate()) {
if (($existedDialog = Dialog::byUsers($dialog->from, $dialog->to)->first()) === null) {
$dialog->save();
$existedDialog = $dialog;
}
$message = new Message();
$message->from = $from->userId;
$message->dialog_id = $existedDialog->id;
$message->text = $msg->message;
if ($message->validate()) {
$message->save();
foreach ($this->clients as $client) {
if ($client->userId == $from->userId || $client->userId == $msg->userTo || $client->isAdmin === true) {
$view = view('chat._message', ['messages' => [$message], 'isAdmin' => $client->isAdmin]);
$sendData = ['action' => Message::CREATE_ACTION_NAME, 'html' => $view->render()];
$client->send(json_encode($sendData));
}
}
}
}
}