getMessage());
}
for ($i=1;$i<=28;$i++){
$builder
->add(
'Answer'.$i,
ChoiceType::class,
array(
'label'=>$questions['Questions'][$i-1],
'choices' => array(
'A - Trifft voll zu' => 4,
'B' => 3,
'C' => 2,
'D' => 1,
'C - Trifft nicht zu ' => 0
)
)
);
}
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'AppBundle\Entity\PfsForm'
)
);
}
}
now the Entity:
answer1;
}
/**
* @param mixed $answer1
*/
public function setAnswer1($answer1)
{
$this->answer1 = $answer1;
}
/**
* @return mixed
*/
public function getAnswer2()
{
return $this->answer2;
}
/**
* @param mixed $answer2
*/
public function setAnswer2($answer2)
{
$this->answer2 = $answer2;
}
/**
* @return mixed
*/
public function getAnswer3()
{
return $this->answer3;
}
/**
* @param mixed $answer3
*/
public function setAnswer3($answer3)
{
$this->answer3 = $answer3;
}
/**
* @return mixed
*/
public function getAnswer4()
{
return $this->answer4;
}
/**
* @param mixed $answer4
*/
public function setAnswer4($answer4)
{
$this->answer4 = $answer4;
}
/**
* @return mixed
*/
public function getAnswer5()
{
return $this->answer5;
}
/**
* @param mixed $answer5
*/
public function setAnswer5($answer5)
{
$this->answer5 = $answer5;
}
/**
* @return mixed
*/
public function getAnswer6()
{
return $this->answer6;
}
/**
* @param mixed $answer6
*/
public function setAnswer6($answer6)
{
$this->answer6 = $answer6;
}
/**
* @return mixed
*/
public function getAnswer7()
{
return $this->answer7;
}
/**
* @param mixed $answer7
*/
public function setAnswer7($answer7)
{
$this->answer7 = $answer7;
}
/**
* @return mixed
*/
public function getAnswer8()
{
return $this->answer8;
}
/**
* @param mixed $answer8
*/
public function setAnswer8($answer8)
{
$this->answer8 = $answer8;
}
/**
* @return mixed
*/
public function getAnswer9()
{
return $this->answer9;
}
/**
* @param mixed $answer9
*/
public function setAnswer9($answer9)
{
$this->answer9 = $answer9;
}
/**
* @return mixed
*/
public function getAnswer10()
{
return $this->answer10;
}
/**
* @param mixed $answer10
*/
public function setAnswer10($answer10)
{
$this->answer10 = $answer10;
}
/**
* @return mixed
*/
public function getAnswer11()
{
return $this->answer11;
}
/**
* @param mixed $answer11
*/
public function setAnswer11($answer11)
{
$this->answer11 = $answer11;
}
/**
* @return mixed
*/
public function getAnswer12()
{
return $this->answer12;
}
/**
* @param mixed $answer12
*/
public function setAnswer12($answer12)
{
$this->answer12 = $answer12;
}
/**
* @return mixed
*/
public function getAnswer13()
{
return $this->answer13;
}
/**
* @param mixed $answer13
*/
public function setAnswer13($answer13)
{
$this->answer13 = $answer13;
}
/**
* @return mixed
*/
public function getAnswer14()
{
return $this->answer14;
}
/**
* @param mixed $answer14
*/
public function setAnswer14($answer14)
{
$this->answer14 = $answer14;
}
/**
* @return mixed
*/
public function getAnswer15()
{
return $this->answer15;
}
/**
* @param mixed $answer15
*/
public function setAnswer15($answer15)
{
$this->answer15 = $answer15;
}
/**
* @return mixed
*/
public function getAnswer16()
{
return $this->answer16;
}
/**
* @param mixed $answer16
*/
public function setAnswer16($answer16)
{
$this->answer16 = $answer16;
}
/**
* @return mixed
*/
public function getAnswer17()
{
return $this->answer17;
}
/**
* @param mixed $answer17
*/
public function setAnswer17($answer17)
{
$this->answer17 = $answer17;
}
/**
* @return mixed
*/
public function getAnswer18()
{
return $this->answer18;
}
/**
* @param mixed $answer18
*/
public function setAnswer18($answer18)
{
$this->answer18 = $answer18;
}
/**
* @return mixed
*/
public function getAnswer19()
{
return $this->answer19;
}
/**
* @param mixed $answer19
*/
public function setAnswer19($answer19)
{
$this->answer19 = $answer19;
}
/**
* @return mixed
*/
public function getAnswer20()
{
return $this->answer20;
}
/**
* @param mixed $answer20
*/
public function setAnswer20($answer20)
{
$this->answer20 = $answer20;
}
/**
* @return mixed
*/
public function getAnswer21()
{
return $this->answer21;
}
/**
* @param mixed $answer21
*/
public function setAnswer21($answer21)
{
$this->answer21 = $answer21;
}
/**
* @return mixed
*/
public function getAnswer22()
{
return $this->answer22;
}
/**
* @param mixed $answer22
*/
public function setAnswer22($answer22)
{
$this->answer22 = $answer22;
}
/**
* @return mixed
*/
public function getAnswer23()
{
return $this->answer23;
}
/**
* @param mixed $answer23
*/
public function setAnswer23($answer23)
{
$this->answer23 = $answer23;
}
/**
* @return mixed
*/
public function getAnswer24()
{
return $this->answer24;
}
/**
* @param mixed $answer24
*/
public function setAnswer24($answer24)
{
$this->answer24 = $answer24;
}
/**
* @return mixed
*/
public function getAnswer25()
{
return $this->answer25;
}
/**
* @param mixed $answer25
*/
public function setAnswer25($answer25)
{
$this->answer25 = $answer25;
}
/**
* @return mixed
*/
public function getAnswer26()
{
return $this->answer26;
}
/**
* @param mixed $answer26
*/
public function setAnswer26($answer26)
{
$this->answer26 = $answer26;
}
/**
* @return mixed
*/
public function getAnswer27()
{
return $this->answer27;
}
/**
* @param mixed $answer27
*/
public function setAnswer27($answer27)
{
$this->answer27 = $answer27;
}
/**
* @return mixed
*/
public function getAnswer28()
{
return $this->answer28;
}
/**
* @param mixed $answer28
*/
public function setAnswer28($answer28)
{
$this->answer28 = $answer28;
}
}
namespace AppBundle\Controller;
use AppBundle\Entity\PfsForm;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Form\PfsFormType;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
class IndexController extends Controller
{
public function startAction()
{
try{
$questions = Yaml::parse(file_get_contents('../web/bundles/framework/yml/quetions.yml'));
}catch(ParseException $e){
printf("Unable to find YML file,%s",$e->getMessage());
}
$pfsForm = new PfsForm();
$formN = $this->createForm(PfsFormType::class, $pfsForm);
return $this->render(
'index.html.twig',array(
'form' => $formN->createView()
)
);
}
}
i try to made an psychology test with symfony. I have 28 questions an 28 answer.
I get the questions out of an YAML file. I made an Form Class, and a contoller to call the Form class. Everything seems to work but i think thats my solution is crappy shit. Can u tell my your opinion to my code?
getMessage());
}
for ($i=1;$i<=28;$i++){
$builder
->add(
'Answer'.$i,
ChoiceType::class,
array(
'label'=>$questions['Questions'][$i-1],
'choices' => array(
'A - Trifft voll zu' => 4,
'B' => 3,
'C' => 2,
'D' => 1,
'C - Trifft nicht zu ' => 0
)
)
);
}
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
array(
'data_class' => 'AppBundle\Entity\PfsForm'
)
);
}
}
now the Entity:
answer1;
}
/**
* @param mixed $answer1
*/
public function setAnswer1($answer1)
{
$this->answer1 = $answer1;
}
/**
* @return mixed
*/
public function getAnswer2()
{
return $this->answer2;
}
/**
* @param mixed $answer2
*/
public function setAnswer2($answer2)
{
$this->answer2 = $answer2;
}
/**
* @return mixed
*/
public function getAnswer3()
{
return $this->answer3;
}
/**
* @param mixed $answer3
*/
public function setAnswer3($answer3)
{
$this->answer3 = $answer3;
}
/**
* @return mixed
*/
public function getAnswer4()
{
return $this->answer4;
}
/**
* @param mixed $answer4
*/
public function setAnswer4($answer4)
{
$this->answer4 = $answer4;
}
/**
* @return mixed
*/
public function getAnswer5()
{
return $this->answer5;
}
/**
* @param mixed $answer5
*/
public function setAnswer5($answer5)
{
$this->answer5 = $answer5;
}
/**
* @return mixed
*/
public function getAnswer6()
{
return $this->answer6;
}
/**
* @param mixed $answer6
*/
public function setAnswer6($answer6)
{
$this->answer6 = $answer6;
}
/**
* @return mixed
*/
public function getAnswer7()
{
return $this->answer7;
}
/**
* @param mixed $answer7
*/
public function setAnswer7($answer7)
{
$this->answer7 = $answer7;
}
/**
* @return mixed
*/
public function getAnswer8()
{
return $this->answer8;
}
/**
* @param mixed $answer8
*/
public function setAnswer8($answer8)
{
$this->answer8 = $answer8;
}
/**
* @return mixed
*/
public function getAnswer9()
{
return $this->answer9;
}
/**
* @param mixed $answer9
*/
public function setAnswer9($answer9)
{
$this->answer9 = $answer9;
}
/**
* @return mixed
*/
public function getAnswer10()
{
return $this->answer10;
}
/**
* @param mixed $answer10
*/
public function setAnswer10($answer10)
{
$this->answer10 = $answer10;
}
/**
* @return mixed
*/
public function getAnswer11()
{
return $this->answer11;
}
/**
* @param mixed $answer11
*/
public function setAnswer11($answer11)
{
$this->answer11 = $answer11;
}
/**
* @return mixed
*/
public function getAnswer12()
{
return $this->answer12;
}
/**
* @param mixed $answer12
*/
public function setAnswer12($answer12)
{
$this->answer12 = $answer12;
}
/**
* @return mixed
*/
public function getAnswer13()
{
return $this->answer13;
}
/**
* @param mixed $answer13
*/
public function setAnswer13($answer13)
{
$this->answer13 = $answer13;
}
/**
* @return mixed
*/
public function getAnswer14()
{
return $this->answer14;
}
/**
* @param mixed $answer14
*/
public function setAnswer14($answer14)
{
$this->answer14 = $answer14;
}
/**
* @return mixed
*/
public function getAnswer15()
{
return $this->answer15;
}
/**
* @param mixed $answer15
*/
public function setAnswer15($answer15)
{
$this->answer15 = $answer15;
}
/**
* @return mixed
*/
public function getAnswer16()
{
return $this->answer16;
}
/**
* @param mixed $answer16
*/
public function setAnswer16($answer16)
{
$this->answer16 = $answer16;
}
/**
* @return mixed
*/
public function getAnswer17()
{
return $this->answer17;
}
/**
* @param mixed $answer17
*/
public function setAnswer17($answer17)
{
$this->answer17 = $answer17;
}
/**
* @return mixed
*/
public function getAnswer18()
{
return $this->answer18;
}
/**
* @param mixed $answer18
*/
public function setAnswer18($answer18)
{
$this->answer18 = $answer18;
}
/**
* @return mixed
*/
public function getAnswer19()
{
return $this->answer19;
}
/**
* @param mixed $answer19
*/
public function setAnswer19($answer19)
{
$this->answer19 = $answer19;
}
/**
* @return mixed
*/
public function getAnswer20()
{
return $this->answer20;
}
/**
* @param mixed $answer20
*/
public function setAnswer20($answer20)
{
$this->answer20 = $answer20;
}
/**
* @return mixed
*/
public function getAnswer21()
{
return $this->answer21;
}
/**
* @param mixed $answer21
*/
public function setAnswer21($answer21)
{
$this->answer21 = $answer21;
}
/**
* @return mixed
*/
public function getAnswer22()
{
return $this->answer22;
}
/**
* @param mixed $answer22
*/
public function setAnswer22($answer22)
{
$this->answer22 = $answer22;
}
/**
* @return mixed
*/
public function getAnswer23()
{
return $this->answer23;
}
/**
* @param mixed $answer23
*/
public function setAnswer23($answer23)
{
$this->answer23 = $answer23;
}
/**
* @return mixed
*/
public function getAnswer24()
{
return $this->answer24;
}
/**
* @param mixed $answer24
*/
public function setAnswer24($answer24)
{
$this->answer24 = $answer24;
}
/**
* @return mixed
*/
public function getAnswer25()
{
return $this->answer25;
}
/**
* @param mixed $answer25
*/
public function setAnswer25($answer25)
{
$this->answer25 = $answer25;
}
/**
* @return mixed
*/
public function getAnswer26()
{
return $this->answer26;
}
/**
* @param mixed $answer26
*/
public function setAnswer26($answer26)
{
$this->answer26 = $answer26;
}
/**
* @return mixed
*/
public function getAnswer27()
{
return $this->answer27;
}
/**
* @param mixed $answer27
*/
public function setAnswer27($answer27)
{
$this->answer27 = $answer27;
}
/**
* @return mixed
*/
public function getAnswer28()
{
return $this->answer28;
}
/**
* @param mixed $answer28
*/
public function setAnswer28($answer28)
{
$this->answer28 = $answer28;
}
}
and in the end the controller:
Do someone have a tip how to build up the entity without the answer1 - answers28 ?
namespace AppBundle\Controller;
use AppBundle\Entity\PfsForm;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use AppBundle\Form\PfsFormType;
use Symfony\Component\BrowserKit\Response;
use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;
class IndexController extends Controller
{
public function startAction()
{
try{
$questions = Yaml::parse(file_get_contents('../web/bundles/framework/yml/quetions.yml'));
}catch(ParseException $e){
printf("Unable to find YML file,%s",$e->getMessage());
}
$pfsForm = new PfsForm();
$formN = $this->createForm(PfsFormType::class, $pfsForm);
return $this->render(
'index.html.twig',array(
'form' => $formN->createView()
)
);
}
}
Thx for your help
Micha
php forms symfony
shareimprove this question
asked Sep 6 '16 at 9:50
freemindghost
27111 gold badge22 silver badges99 bronze badges
show 4 more comments