示例#1
0
 public function executeSendMessage(sfWebRequest $request)
 {
     $this->forward404Unless($request->isMethod('POST'));
     $form = new MessageForm($this->getUser()->getAttribute('id'));
     $form->bind($request->getParameter('message'));
     if ($form->isValid()) {
         $thread = new Thread();
         $thread->subject = $request->getPostParameter('message[subject]');
         $thread->recipients = json_encode(array($this->getUser()->getAttribute('id'), $request->getPostParameter('message[recipients]')));
         $thread->save();
         $message = new Message();
         $message->message_id = md5(date(DateTime::ISO8601));
         $message->thread_id = $thread->thread_id;
         $message->author_id = $this->getUser()->getAttribute('id');
         $message->body = $request->getPostParameter('message[message]');
         $message->save();
         $this->redirectWithInfo('Your message was successfully sent.', 'messages/index');
     }
     $this->redirectWithInfo('An error occured sending your message.  Please try again later.');
 }