Browse Source

Découpage des templates et action de 'recherche'.

bastien 12 years ago
parent
commit
f68c3573f8

+ 31 - 0
src/Muzich/CoreBundle/Controller/SearchController.php View File

@@ -0,0 +1,31 @@
1
+<?php
2
+
3
+namespace Muzich\CoreBundle\Controller;
4
+
5
+use Muzich\CoreBundle\lib\Controller;
6
+use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
7
+
8
+use Muzich\CoreBundle\Searcher\ElementSearcher;
9
+use Doctrine\ORM\Query;
10
+
11
+class SearchController extends Controller
12
+{
13
+  
14
+  /**
15
+   * 
16
+   */
17
+  public function searchelementsAction(ElementSearcher $search, $template = 'default')
18
+  {
19
+    $elements = $this->getDoctrine()
20
+      ->getRepository('MuzichCoreBundle:Element')
21
+      ->findBySearch($search)
22
+      ->execute()
23
+    ;
24
+    
25
+    return $this->render(
26
+      'MuzichCoreBundle:SearchElement:default.html.twig', 
27
+      array('elements' => $elements)
28
+    );
29
+  }   
30
+  
31
+}

+ 16 - 0
src/Muzich/CoreBundle/Resources/views/SearchElement/default.html.twig View File

@@ -0,0 +1,16 @@
1
+<ul>
2
+  {% for element in elements %} 
3
+    <li>
4
+      {{element.name}} ({{element.owner.username}})
5
+        <a href="{{element.url}}" target="_blank">link</a>
6
+        <ul>
7
+          {% for tag in element.tags %} 
8
+            <li>
9
+              {{tag.name}}
10
+            </li>
11
+          {% endfor %} 
12
+        </ul>
13
+        
14
+    </li>
15
+  {% endfor %} 
16
+</ul>

+ 1 - 9
src/Muzich/HomeBundle/Controller/HomeController.php View File

@@ -12,18 +12,10 @@ use Doctrine\ORM\Query;
12 12
 class HomeController extends Controller
13 13
 {
14 14
   /**
15
-   * @Route("/")
16 15
    * @Template()
17 16
    */
18 17
   public function indexAction()
19 18
   {        
20
-    $user = $this->getUser();
21
-       
22
-    $query = $this->getDoctrine()
23
-      ->getRepository('MuzichCoreBundle:Element')
24
-      ->findBySearch($this->getElementSearcher($user->getId()))
25
-    ;
26
-    
27
-    return array('elements' => $query->execute());
19
+    return array('search' => $this->getElementSearcher($this->getUser()->getId()));
28 20
   }
29 21
 }

+ 1 - 17
src/Muzich/HomeBundle/Resources/views/Home/index.html.twig View File

@@ -4,22 +4,6 @@
4 4
 
5 5
 {% block content %}
6 6
     
7
-<ul>
8
-  {% for element in elements %} 
9
-    <li>
10
-      {{element.name}} ({{element.owner.username}})
11
-        <a href="{{element.url}}" target="_blank">link</a>
12
-        <ul>
13
-          {% for tag in element.tags %} 
14
-            <li>
15
-              {{tag.name}}
16
-            </li>
17
-          {% endfor %} 
18
-        </ul>
19
-        
20
-    </li>
21
-  {% endfor %} 
22
-</ul>
23
-    
7
+  {% render "MuzichCoreBundle:Search:searchelements" with { 'search': search } %}
24 8
     
25 9
 {% endblock %}