当前位置: 首页>>代码示例>>PHP>>正文


PHP messages::save方法代码示例

本文整理汇总了PHP中messages::save方法的典型用法代码示例。如果您正苦于以下问题:PHP messages::save方法的具体用法?PHP messages::save怎么用?PHP messages::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在messages的用法示例。


在下文中一共展示了messages::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sendAction

 /**
  * The Send Action: This checks that the HTTP request is post, decodes the JSON expected and then checks
  * both the sending user's authentication (via their id and apiKey) and then checks the recipient exsits.
  * Should both of these conditions be true, the method will save the message in the database and return
  * with the message ID, Sender, Receiver, Content and Timestamp.
  */
 public function sendAction()
 {
     $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);
     $request = new \Phalcon\Http\Request();
     if ($request->isPost()) {
         $data = json_decode(file_get_contents('php://input'), true);
         $user = users::findFirst(array("conditions" => 'id = :idVal: and apiKey = :keyVal:', 'bind' => array('idVal' => $data['userid'], 'keyVal' => $data['user_api_key'])));
         $recipient = users::findFirst(array("conditions" => 'id = :idVal:', 'bind' => array('idVal' => $data['recipient'])));
         if ($user && $recipient) {
             $message = new messages();
             $message->sender = $user->id;
             $message->receiver = $recipient->id;
             $message->content = $data['message'];
             if ($message->save()) {
                 $data = array();
                 $data['id'] = $message->id;
                 $data['sender'] = $message->sender;
                 $data['receiver'] = $message->receiver;
                 $data['content'] = $message->content;
                 $data['timestamp'] = $message->timestamp;
                 if ($recipient->regID == "NULL") {
                     $data['type'] = "PULL";
                 } else {
                     $this->sendToGCM($message, $recipient);
                     $data['type'] = "PUSH";
                 }
                 $array = $data;
                 echo json_encode($array);
             } else {
                 echo $message->getMessages();
             }
             $messageDownload = new downloadedmessages();
             $messageDownload->messageID = $message->id;
             $messageDownload->userID = $user->id;
             $messageDownload->save();
         }
     }
 }
开发者ID:ben-freke,项目名称:ChatLongerWebAPI,代码行数:44,代码来源:MessagesController.php

示例2: create

 public function create()
 {
     $users = User::where('username', Input::get('toId'))->orWhere('email', Input::get('toId'));
     if ($users->count() == 0) {
         echo $this->panelInit->language['userisntExist'];
         exit;
     }
     $users = $users->first();
     $messagesList = messagesList::where('userId', $this->data['users']->id)->where('toId', $users->id);
     if ($messagesList->count() == 0) {
         $messagesList = new messagesList();
         $messagesList->userId = $this->data['users']->id;
         $messagesList->toId = $users->id;
     } else {
         $messagesList = $messagesList->first();
     }
     $messagesList->lastMessage = Input::get('messageText');
     $messagesList->lastMessageDate = time();
     $messagesList->messageStatus = 0;
     $messagesList->save();
     $toReturnId = $messagesList->id;
     $messagesList_ = messagesList::where('userId', $users->id)->where('toId', $this->data['users']->id);
     if ($messagesList_->count() == 0) {
         $messagesList_ = new messagesList();
         $messagesList_->userId = $users->id;
         $messagesList_->toId = $this->data['users']->id;
     } else {
         $messagesList_ = $messagesList_->first();
     }
     $messagesList_->lastMessage = Input::get('messageText');
     $messagesList_->lastMessageDate = time();
     $messagesList_->messageStatus = 1;
     $messagesList_->save();
     $toReturnId_ = $messagesList_->id;
     $messages = new messages();
     $messages->messageId = $toReturnId;
     $messages->userId = $this->data['users']->id;
     $messages->fromId = $this->data['users']->id;
     $messages->toId = $users->id;
     $messages->messageText = Input::get('messageText');
     $messages->dateSent = time();
     $messages->save();
     $messages = new messages();
     $messages->messageId = $toReturnId_;
     $messages->userId = $users->id;
     $messages->fromId = $this->data['users']->id;
     $messages->toId = $users->id;
     $messages->messageText = Input::get('messageText');
     $messages->dateSent = time();
     $messages->save();
     return json_encode(array('messageId' => $toReturnId));
 }
开发者ID:schoex,项目名称:Campusmate,代码行数:52,代码来源:MessagesController.php


注:本文中的messages::save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。