Skip to content

Instantly share code, notes, and snippets.

@kurozumi
Created December 2, 2020 22:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save kurozumi/427ae6643fbd5cbed61fa7514ac50263 to your computer and use it in GitHub Desktop.
アンケート用のコントローラー
<?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