So habe ich diese ChoiceType Form
, die die Elemente sortieren wird:Griff Anfrage: ChoicesType
$sort = $this->createForm(ChoiceType::class, NULL, array(
'choices' => array(
'...' => 'default',
'A-Z' => 'title_up',
'Z-A' => 'title_down',
'Price low to high' => 'price_up',
'Price high to low' => 'price_down',
),
));
ich die Choices
so, dass, wenn einer von ihnen verwenden möchten, aus dem Dropdown-Menü ausgewählt wird, wird dies tun: $products = "SELECT a FROM AppBundle:Product a ORDER BY a.title ASC"
.
Ich versuchte dies:
$sort->handleRequest($request);
if($sort->isSubmitted() && $sort->isValid()) {
if (isset($default)) {
$products = "SELECT a FROM AppBundle:Product a ORDER BY a.title ASC";
return $this->render('AppBundle:main:index.html.twig', array('products' => $products,));
}
}
Aber $default
nicht funktioniert, da nicht definiert ist. Ich weiß nicht, wie man auf die choices
zugreift, also kann ich sie zu einer if
Aussage führen.