Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
アンケート用のコントローラー
<?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