/
ForumController.php
46 lines (39 loc) · 1.73 KB
/
ForumController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
namespace Herzult\Bundle\ForumBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Herzult\Bundle\ForumBundle\Form\SearchFormType;
use Herzult\Bundle\ForumBundle\Search\Search;
class ForumController extends Controller
{
public function indexAction()
{
$template = sprintf('%s:index.html.%s', $this->container->getParameter('herzult_forum.templating.location.forum'), $this->getRenderer());
return $this->get('templating')->renderResponse($template, array(
'page' => $this->get('request')->query->get('page', 1)
));
}
public function searchAction()
{
$search = new Search();
$form = $this->get('form.factory')->create(new SearchFormType(), $search);
$form->bind(array('query' => $this->get('request')->query->get('q')));
$query = $form->getData()->getQuery();
$results = null;
if ($form->isValid()) {
$page = $this->get('request')->query->get('page', 1);
$results = $this->get('herzult_forum.repository.post')->search($query, true);
$results->setCurrentPage($page);
$results->setMaxPerPage($this->container->getParameter('herzult_forum.paginator.search_results_per_page'));
}
$template = sprintf('%s:search.html.%s', $this->container->getParameter('herzult_forum.templating.location.forum'), $this->getRenderer());
return $this->get('templating')->renderResponse($template, array(
'form' => $form->createView(),
'results' => $results,
'query' => $query
));
}
protected function getRenderer()
{
return $this->container->getParameter('herzult_forum.templating.engine');
}
}