Hello, I tried Symfony and I am very new. I am looking for an elegant way to filter lists.
Let me explain:
I have two objects: Link and Tag. They are in several respects.
In my index view, I created this form. I did findAll () to get all my tags for selection:
<form method="GET" action="">
<input class="btn btn-default" type="submit"/>
<select name="tags[]" class="selectpicker" multiple="yes">
{% for tag in tags %}
<option value="{{ tag.id }}"> {{ tag.title }}</option>
{% endfor %}
</select>
</form>
This is how I can capture the whole DESC link order:
$links = $em->getRepository('TestDefaultBundle:Link')->findBy(
array(),
array('id' => 'desc')
);
How can I collect the selected tags (in the controller) and capture all link filters with these selected tags.
Another question that I know, we can create a form for an object, but what about this form?
EDIT
This is my indexAction:
public function indexAction(Request $request)
{
$em = $this->getDoctrine()->getManager();
$tags = $em->getRepository('LanCrmBundle:LinkTag')->findAll();
$form = $this->createFormBuilder()
->add('tags', 'entity', array(
'class' => 'LanCrmBundle:LinkTag',
'multiple' => true,
'expanded' => false,
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u')
->orderBy('u.title', 'ASC');
}
))
->add('OK', 'submit')
->getForm()
;
$form->handleRequest($request);
if ($form->isValid()) {
$data = $form->getData();
$links = $em->getRepository('LanCrmBundle:Link')->findBy(
array(),
array('id' => 'desc')
);
} else {
$links = $em->getRepository('LanCrmBundle:Link')->findBy(
array(),
array('id' => 'desc')
);
}
$paginator = $this->get('knp_paginator');
$pagination = $paginator->paginate(
$links,
$this->get('request')->query->get('page', 1),
4
);
return $this->render('LanCrmBundle:Link:index.html.twig', array(
'pagination' => $pagination,
'tags' => $tags,
'form' => $form->createView()
));
}
I have this error:
"__toString()" "Lan\CrmBundle\Entity\LinkTag", . , "" .
StringCastException: "__toString()" "Lan\CrmBundle\Entity\LinkTag", . , "" .