Skip to content

Commit

Permalink
[5-4] indexPostAction()の修正
Browse files Browse the repository at this point in the history
  • Loading branch information
hidenorigoto committed Nov 4, 2015
1 parent 817ac83 commit b9718f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
30 changes: 30 additions & 0 deletions docs/lists/ch05/05-04.txt
@@ -0,0 +1,30 @@
public function indexPostAction(Request $request)
{
...
$inquiry = $form->getData();

$em = $this->getDoctrine()->getManager();
$em->persist($inquiry);
$em->flush();

$message = \Swift_Message::newInstance()
->setSubject('Webサイトからのお問い合わせ')
->setFrom('webmaster@example.com')
->setTo('admin@example.com')
->setBody(
$this->renderView(
'mail/inquiry.txt.twig',
['data' => $inquiry]
)
);

$this->get('mailer')->send($message);

return $this->redirect(
$this->generateUrl('app_inquiry_complete'));
}

return $this->render('Inquiry/index.html.twig',
['form' => $form->createView()]
);
}
11 changes: 2 additions & 9 deletions src/AppBundle/Controller/InquiryController.php
Expand Up @@ -34,14 +34,7 @@ public function indexPostAction(Request $request)
$form->handleRequest($request);
if ($form->isValid())
{
$data = $form->getData();

$inquiry = new Inquiry();
$inquiry->setName($data['name']);
$inquiry->setEmail($data['email']);
$inquiry->setTel($data['tel']);
$inquiry->setType($data['type']);
$inquiry->setContent($data['content']);
$inquiry = $form->getData();

$em = $this->getDoctrine()->getManager();
$em->persist($inquiry);
Expand All @@ -54,7 +47,7 @@ public function indexPostAction(Request $request)
->setBody(
$this->renderView(
'mail/inquiry.txt.twig',
['data' => $data]
['data' => $inquiry]
)
);

Expand Down

0 comments on commit b9718f3

Please sign in to comment.