title: PHP - Slim Framework: Best practice with a lot of code inside routes closures
body: <p>I'm using <a href="http://www.slimframework.com" rel="nofollow">Slim</a>. In the <a href="http://docs.slimframework.com/" rel="nofollow">documentation</a> they only show examples working with only one index.php file, which has really little functionality for every route. For example:</p>
  
  <pre><code>$app = new \Slim\Slim();
  $app-&gt;get('/books/:id', function ($id) {
      //Show book identified by $id
  });
  </code></pre>
  
  <p>But in my case, my index.php file is getting bigger and bigger, now I have a lot of code for most routes, what is the best practice in this case? to include files inside the routes closures? What happens with the scope of global variables, like DB connection or app config? Thank you</p>