Skip to content

Commit

Permalink
[5-2] indexPostAction()に保存処理を記述
Browse files Browse the repository at this point in the history
  • Loading branch information
hidenorigoto committed Nov 4, 2015
1 parent 00ea09e commit dccb22a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/lists/ch05/05-02.txt
@@ -0,0 +1,25 @@
use AppBundle\Entity\Inquiry;
...
public function indexPostAction(Request $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']);

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

$message = \Swift_Message::newInstance()
...
}
...
}
12 changes: 12 additions & 0 deletions src/AppBundle/Controller/InquiryController.php
Expand Up @@ -6,6 +6,7 @@
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Inquiry;

/**
* @Route("/inquiry")
Expand Down Expand Up @@ -35,6 +36,17 @@ public function indexPostAction(Request $request)
{
$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']);

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

$message = \Swift_Message::newInstance()
->setSubject('Webサイトからのお問い合わせ')
->setFrom('webmaster@example.com')
Expand Down

0 comments on commit dccb22a

Please sign in to comment.