title: Site Navigation Controller in Fat Free Framework
body: <p>I am trying to create a separate Controller to handle site navigation, which is pretty much constant throughout the site, like Main Navigation and Sidebar Navigation and possible Footer Navigation. </p>
  
  <p>I cannot figure how I should do it without specifically creating a route for this, my assumption is that: if the navigation controller is something that should work on its own and anywhere across my site, which means that I cannot specify some sort of rout as it will not work on every page unless I call it in other methods.</p>
  
  <h2>Routing</h2>
  
  <pre><code>GET / = MainController-&gt;render
  GET /@category_slug = CategoryController-&gt;CategorySlug
  </code></pre>
  
  <p>My current code is as follows:</p>
  
  <pre><code>class CategoryController extends Controller
  {
      public function navigation(){
          $categories = new Categories($this-&gt;db);
          $cat = $categories-&gt;all();
          $this-&gt;f3-&gt;set('categories',$cat);
      }
  
      function CategorySlug(){
          $category_slug = $this-&gt;f3-&gt;get('PARAMS.category_slug');
          $categories = new Categories($this-&gt;db);
          $cat = $categories-&gt;getBySlug($category_slug);
          $header_location = $cat[0]['category_slug'];
          if($category_slug != $header_location &amp;&amp; !empty($header_location)){
              header("HTTP/1.1 301 Moved Permanently");
              header("Location: $header_location");
          }else if(empty($header_location) || $cat[0]['category_id'] != $cat[0]['parent_category_id']){
              $this-&gt;f3-&gt;error(404);
          }else{
              $this-&gt;f3-&gt;set('category',$cat[0]);
          }
          $this-&gt;f3-&gt;set('view','mainCategory.html');
          $this-&gt;navigation();
          echo \Template::instance()-&gt;render('mainLayout.html');
      }
  }
  </code></pre>
  
  <p>So as youi can see from the code, the first method is my site navigation, which I need to call in the second method to display the navigation on the Category Page. Same goes for my Home page, here is my code for it:</p>
  
  <pre><code>class MainController extends Controller
  {
  
      function render(){
          $classNav = new CategoryController();
          $classNav-&gt;navigation();
          $this-&gt;f3-&gt;set('view','mainHome.html');
          echo \Template::instance()-&gt;render('mainLayout.html');
      }
  }
  </code></pre>
  
  <p>Any help or pointers please</p>