Created
December 2, 2020 22:42
-
-
Save kurozumi/427ae6643fbd5cbed61fa7514ac50263 to your computer and use it in GitHub Desktop.
アンケート用のコントローラー
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Customize\Controller; | |
use Customize\Entity\Questionnaire; | |
use Customize\Form\FormFlow\QuestionnaireFlow; | |
use Eccube\Controller\AbstractController; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
use Symfony\Component\Routing\Annotation\Route; | |
class QuestionnaireController extends AbstractController | |
{ | |
/** | |
* @param QuestionnaireFlow $flow | |
* @return \Symfony\Component\HttpFoundation\RedirectResponse | |
* | |
* @Route("/questionnaire", name="questionnaire") | |
* @Template("Questionnaire/index.twig") | |
*/ | |
public function index(QuestionnaireFlow $flow) | |
{ | |
$formData = new Questionnaire(); | |
$flow->bind($formData); | |
$form = $flow->createForm(); | |
if ($flow->isValid($form)) { | |
$flow->saveCurrentStepData($form); | |
if($flow->nextStep()) { | |
// 次のステップ用のフォームを作成 | |
$form = $flow->createForm(); | |
} else { | |
// データを保存 | |
$this->entityManager->persist($formData); | |
$this->entityManager->flush(); | |
// セッションからデータを削除 | |
$flow->reset(); | |
return $this->redirectToRoute('questionnaire'); | |
} | |
} | |
return [ | |
'form' => $form->createView(), | |
'flow' => $flow | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment