开发者

"Reply " to message in symfony forms

I use symfony 1.4.11 with Doctrine. I have private messages in my site, And I want to make possibility , that user can "reply" for a message. I try change "edit" method, but I do not now is this a good idea. How to make it?Now I have

$this->forward404Unless(
    $messages = Doctrine_Core::getTable('Messages')->find(array($request->getParameter('id'))),
    sprintf('Object messages does not exist (%s).', $request->getParameter('id'))
);

$messages->setMessage('') ;
$messages->setTitle('Re:'.$messages->getTitle()) ;  
开发者_C百科$messages->setRecipientId($messages->getSenderId()) ;
$this->form = new MessagesForm($messages);

But it do not create new message , it only edit...


Add a reply action:

public function executeReply(sfWebRequest $request)
{
  $originalMessage = Doctrine_Core::getTable('Messages')->find(array($request['id']));
  $this->forward404Unless($originalMessage, sprintf('Object messages does not exist (%s).', $request['id']));

  $reply = new Message();
  $reply->setTitle('Re:'.$originalMessage->getTitle());  
  $reply->setRecipientId($originalMessage->getSenderId());
  $this->form = new MessagesForm($reply);
}

Additional notes:

  • You could modify your existing new action and add check to see if an original message id is provided.
  • It's a database convention to always name your objects in the singular. So your model should be called Message not Messages.
  • If there are many properties of the original message that should be copied, you can use the copy method on Doctrine_Record instead of making a new one.
  • You probably want to add a self relation as mentioned by dxb so that you can track what the message is a reply to. You may want to track both the thread and the reply to, depending on what your requirements are.


Maybe you have to design a self referenced table message : a reply is a new message which refer to the previous.

http://www.doctrine-project.org/projects/orm/1.2/docs/manual/defining-models/ru#relationships:join-table-associations:self-referencing-nest-relations:equal-nest-relations

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜