當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。