Choice of the Form

This commit is contained in:
Marc Ducobu 2014-11-08 16:59:36 +01:00
parent 005e56c72a
commit 1ea54c39b3
2 changed files with 31 additions and 9 deletions

View File

@ -19,16 +19,38 @@ class ReportController extends Controller
* Lists all Report entities.
*
*/
public function indexAction()
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$entities = $em->getRepository('ChillReportBundle:Report')->findAll();
$cFGroups = $em->getRepository('ChillCustomFieldsBundle:CustomFieldsGroup')
->findByEntity('Chill\ReportBundle\Entity\Report');
$cFGroupsChoice = array();
foreach ($cFGroups as $g) {
$cFGroupsChoice[$g->getId()] = $g->getName($request->getLocale());
}
$form = $this->get('form.factory')
->createNamedBuilder(null, 'form', null, array(
'method' => 'GET',
'action' => $this->generateUrl('report_new'),
'csrf_protection' => false
))
->add('type', 'choice', array(
'choices' => $cFGroupsChoice
))
->getForm();
return $this->render('ChillReportBundle:Report:index.html.twig', array(
'entities' => $entities,
'form' => $form->createView()
));
}
/**
* Creates a new Report entity.
*

View File

@ -41,11 +41,11 @@
</tbody>
</table>
<ul>
<li>
<a href="{{ path('report_new') }}">
Create a new entry
</a>
</li>
</ul>
{% endblock %}
{{ form_start(form) }}
{{ form_row(form) }}
<button type="submit">
Create a new report
</button>
{{ form_end(form) }}
{% endblock %}