html - Can the href of a link be changed dynamically inside a twig temple in Symfony 2 -
i've been working on menu in site while , i've been asking lot of question menu. idea menu have select project , clicking modify or delete button while do¸what needs selected project.
so far, found 2 possible ways this:
-do form select , 3 buttons (add, modify, delete)
-do link each button , generate select in twig loop
i think more logical option second one, problem link must send id of selected project.
since twig generate html you, once it's generated, twig cannot again, can't twig change link according selected project!
i know there must way solve javascript, but, really, rather prefer using form insteed, heaven if seems kind of weird in situation, because form knows project selected , it's easy use controller redirect on next page modify button , delete project.
if link page change, need change javascript wouldn't happen oder sollution.
so, there other way still make want links without javascript? if not, i'll take other solution.
define form way:
$form = $this->createformbuilder($task) ->add('project', 'choice', array( 'choices' => array('1' => 'project 1', '3' => 'project 2') )) ->add('delete', 'submit', array('label' => 'remove project')) ->add('update', 'submit', array('label' => 'update project')) ->getform();
choices
can entity
field type.
then in controller:
$projectid = $form->get('project'); if ($form->get('delete')->isclicked()) { // ... } elseif ($form->get('update')->isclicked()){ // ... }
Comments
Post a Comment