“回复”以 symfony 形式发送消息

发布于 2024-11-18 12:44:36 字数 568 浏览 2 评论 0 原文

我使用 symfony 1.4.11 和 Doctrine。我的网站中有私人消息,我希望用户可以“回复”消息。我尝试更改“编辑”方法,但我现在不知道这是一个好主意。如何制作?现在我有了

$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);

,但它不会创建新消息,它只会编辑...

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

早茶月光 2024-11-25 12:44:36

添加回复操作:

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);
}

附加说明:

  • 您可以修改现有的新操作并添加检查以查看是否提供了原始消息 ID。
  • 数据库约定始终以单数命名对象。所以你的模型应该被称为消息而不是消息。
  • 如果原始消息有许多属性需要复制,您可以使用 Doctrine_Record 上的 copy 方法,而不是创建一个新属性。
  • 您可能想要添加 dxb 提到的自关系,以便您可以跟踪消息的回复内容。您可能想要跟踪主题和回复,具体取决于您的要求。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文