title: Symfony2 - call a controller from within a view
body: <p>I want to have a view call upon controllers from within it. Similar to C#.NET MVC 4.0.</p>
  
  <p>In my view I may have:</p>
  
  <ul>
  <li>Header</li>
  <li>Admin navigation</li>
  <li>Normal navigation</li>
  <li>Page content ( divided into three parts, list of something, list of something else, main page content</li>
  <li>Footer</li>
  </ul>
  
  <p>All of these parts are reusable sections. I'm most likely going to always have a Header, Normal nav and Footer part of my page.</p>
  
  <p>My controller does database calls to fetch the model and pump it to my view.
  I don't want to ever have to worry about this code again so I just want to call the result of this controller from any view: pseudo code:</p>
  
  <p><strong>Template view: base.html.php</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
          &lt;title&gt;&lt;?php $view['slots']-&gt;output('title', 'Welcome!') ?&gt;&lt;/title&gt;
          &lt;?php $view['slots']-&gt;output('stylesheets') ?&gt;
          &lt;link rel="shortcut icon" href="&lt;?php echo $view['assets']-&gt;getUrl('favicon.ico') ?&gt;" /&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;?php echo $view['actions']-&gt;render(SomethingBundle:Navigation:index); ?&gt; // THIS LINE HERE
          &lt;h1&gt;&lt;?php $view['slots']-&gt;output('pageTitle') ?&gt;&lt;/h1&gt;
          &lt;?php $view['slots']-&gt;output('_content') ?&gt;
      &lt;/body&gt;
  </code></pre>
  
  <p>So this is my template page, and I expect to be able to include the navigation view in this page, but the navigation requires a model so it also depends on the navigation controller.
      </p>
  
  <p><strong>Navigation controller: Controller/NavigationController</strong></p>
  
  <pre><code>class NavigationController extends Controller
      {
          public function indexAction()
          {
              return $this-&gt;render(SomethingBundle:Navigation:index.html.php');
          }
      }
  </code></pre>
  
  <p><strong>Navigation View: index.html.php</strong></p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;Home&lt;/li&gt;
      &lt;li&gt;About&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Obviously the above code does not work. How do you include the result of a controller in a view?</p>
  
  <p>the error I get from the above code is:</p>
  
  <pre><code>[2/2] NotFoundHttpException: No route found for "GET Navigation:index"  -+  
  [1/2] ResourceNotFoundException:   -+ 
  </code></pre>