Переглянути джерело

[WebProfilerBundle] Better handling of queries with an empty result

Victor Berchet 14 роки тому
батько
коміт
f49a30c366

+ 1 - 1
src/Symfony/Bundle/WebProfilerBundle/Controller/ProfilerController.php

@@ -235,7 +235,7 @@ class ProfilerController extends ContainerAware
 
         $tokens = $profiler->find($ip, $url, $limit);
 
-        return new RedirectResponse($this->container->get('router')->generate('_profiler_search_results', array('token' => $tokens ? $tokens[0]['token'] : '')));
+        return new RedirectResponse($this->container->get('router')->generate('_profiler_search_results', array('token' => $tokens ? $tokens[0]['token'] : 'empty')));
     }
 
     protected function getTemplateNames($profiler)

+ 10 - 8
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/layout.html.twig

@@ -7,14 +7,16 @@
     <div id="content">
         {% include 'WebProfilerBundle:Profiler:header.html.twig' only %}
 
-        <div class="resume">
-            <p>
-                <strong><a href="{{ profiler.url }}">{{ profiler.url }}</a></strong>
-                <span class="date">
-                    <strong>by {{ profiler.ip }}</strong> at <strong>{{ profiler.time|date('r') }}</strong>
-                </span>
-            </p>
-        </div>
+        {% if not profiler.isempty %}
+            <div class="resume">
+                <p>
+                    <strong><a href="{{ profiler.url }}">{{ profiler.url }}</a></strong>
+                    <span class="date">
+                        <strong>by {{ profiler.ip }}</strong> at <strong>{{ profiler.time|date('r') }}</strong>
+                    </span>
+                </p>
+            </div>
+        {% endif %}
 
         <div class="main">
     

+ 21 - 14
src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/results.html.twig

@@ -3,20 +3,27 @@
 {% block panel %}
     <h2>Search Results</h2>
 
-    <table>
-        <tr>
-            <th>Token</th>
-            <th>IP</th>
-            <th>URL</th>
-            <th>Time</th>
-        </tr>
-        {% for elements in tokens %}
+    {% if tokens %}
+        <table>
             <tr>
-                <td><a href="{{ path('_profiler', { 'token': elements.token }) }}">{{ elements.token }}</a></td>
-                <td>{{ elements.ip }}</td>
-                <td>{{ elements.url }}</td>
-                <td>{{ elements.time|date('r') }}</td>
+                <th>Token</th>
+                <th>IP</th>
+                <th>URL</th>
+                <th>Time</th>
             </tr>
-        {% endfor %}
-    </table>
+            {% for elements in tokens %}
+                <tr>
+                    <td><a href="{{ path('_profiler', { 'token': elements.token }) }}">{{ elements.token }}</a></td>
+                    <td>{{ elements.ip }}</td>
+                    <td>{{ elements.url }}</td>
+                    <td>{{ elements.time|date('r') }}</td>
+                </tr>
+            {% endfor %}
+        </table>
+    {% else %}
+        <p>
+            <em>The query returned no result.</em>
+        </p>
+    {% endif %}
+
 {% endblock %}