title: Slim Framework: routes and controllers
body: <p>Originally, my Slim Framework app had the classic structure</p>
  
  <p>(index.php)</p>
  
  <pre><code>&lt;?php
  $app = new \Slim\Slim();
  $app-&gt;get('/hello/:name', function ($name) {
      echo "Hello, $name";
  });
  $app-&gt;run();
  </code></pre>
  
  <p>But as I added more routes and groups of routes, I moved to a controller based approach:</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
  $app = new \Slim\Slim();
  $app-&gt;get('/hello/:name', 'HelloController::hello');
  $app-&gt;run();
  </code></pre>
  
  <p>HelloController.php</p>
  
  <pre><code>&lt;?php
  class HelloController {
      public static function hello($name) {
          echo "Hello, $name";
      }
  }
  </code></pre>
  
  <p>This works, and it had been helpful to organize my app structure, while at the same time lets me build unit tests for each controler method. </p>
  
  <p>However, I'm not sure this is the right way. I feel like I'm mocking Silex's <code>mount</code> method on a sui generis basis, and that can't be good. Using the $app context inside each Controller method requires me to use \Slim\Slim::getInstance(), which seems less efficient than just using $app like a closure can.</p>
  
  <p>So... is there a solution allowing for both efficiency and order, or does efficiency come at the cost of route/closure nightmare?</p>