What about using an embedded controller?
Here's the short example taken from Symfony's documentation page.
You have a controller that returns and renders some output:
// src/Acme/ArticleBundle/Controller/ArticleController.php
class ArticleController extends Controller
{
public function recentArticlesAction($max = 3)
{
// make a database call or other logic
// to get the "$max" most recent articles
$articles = ...;
return $this->render(
'AcmeArticleBundle:Article:recentList.html.twig',
array('articles' => $articles)
);
}
}
In this example, it renders a view:
{# src/Acme/ArticleBundle/Resources/views/Article/recentList.html.twig #}
{% for article in articles %}
<a href="/article/{{ article.slug }}">
{{ article.title }}
</a>
{% endfor %}
and in the view you'd like to embed controller's action:
{# app/Resources/views/base.html.twig #}
{# ... #}
<div id="sidebar">
{{ render(controller('AcmeArticleBundle:Article:recentArticles', {
'max': 3
})) }}
</div>
The docs page also says that you should use and embedded controllers when you need data that you don't have access to in a template. From my point of view, it's perfect for creating widgets, some statistics and so on.
Hope this helps.
Edit
To make this answer more accurate to your issue, here's the solution I'd use:
- You'll need a controller, let's call it
SearchController
- In the controller's
renderForm()
method, you need to create a form and pass it to the view - Form's action attribute should point to
resultAction()
method where you can fetch the results from your data storage and display result to the end user.