denys281
denys281

Reputation: 2014

"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()) ;  
$messages->setRecipientId($messages->getSenderId()) ;
$this->form = new MessagesForm($messages);

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

Upvotes: 0

Views: 235

Answers (2)

Jeremy Kauffman
Jeremy Kauffman

Reputation: 10413

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.

Upvotes: 3

dxb
dxb

Reputation: 931

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

Upvotes: 1

Related Questions