title: slim framework - categorise routes into different files?
body: <p>How can I categorise routes in Slim Framework?</p>
  
  <p>I have these basic/ front routes in my public dir,</p>
  
  <pre><code>$app-&gt;get('/about', function () use ($app, $log) {
      echo "&lt;h1&gt;About ", $app-&gt;config('name'), "&lt;/h1&gt;";
  });
  
  $app-&gt;get('/admin', function () use ($app, $log) {
      echo 'admin area';
      require dirname(__FILE__) . '/../src/Admin/index.php';
  });
  
  // To generic
  $app-&gt;get('/', function () use ($app, $log) {
      echo '&lt;h1&gt;Welcome to ', $app-&gt;config('name'), '&lt;/h1&gt;';
  });
  
  // Important: run the app ;)
  $app-&gt;run();
  </code></pre>
  
  <p>As you can see that when the route is on <code>/admin</code>, it will load the <code>index.php</code> in <strong>Admin</strong> directory.</p>
  
  <p>Admin/index.php,</p>
  
  <pre><code>    // API group
      $app-&gt;group('/admin', function () use ($app) {
  
          // Contact group
          $app-&gt;group('/contact', function () use ($app) {
  
              // Get contact with ID
              $app-&gt;get('/contacts', function () {
                  echo 'list of contacts';
              });
  
              // Get contact with ID
              $app-&gt;get('/contacts/:id', function ($id) {
                  echo 'get contact of ' . $id;
              });
  
              // Update contact with ID
              $app-&gt;put('/contacts/:id', function ($id) {
                  echo 'update contact of ' . $id;
              });
  
              // Delete contact with ID
              $app-&gt;delete('/contacts/:id', function ($id) {
                  echo 'delete contact of ' . $id;
              });
  
          });
  
          // Article group
          $app-&gt;group('/article', function () use ($app) {
  
              // Get article with ID
              $app-&gt;get('/articles', function () {
                  echo 'list of articles';
              });
  
              // Get article with ID
              $app-&gt;get('/articles/:id', function ($id) {
                  echo 'get article of ' . $id;
              });
  
              // Update article with ID
              $app-&gt;put('/articles/:id', function ($id) {
                  echo 'update article of ' . $id;
              });
  
              // Delete article with ID
              $app-&gt;delete('/articles/:id', function ($id) {
                  echo 'delete contact of ' . $id;
              });
  
          });
  
      });
  </code></pre>
  
  <p>Let's say I have article, contact, etc modules in my admin area. In each of these modules I have routes for get, put, delete. So I group them by module as in <code>Admin/index.php</code>. But I get 404 page not found, when I request these modules on my url, for instance <code>http://{localhost}/admin/contact</code> I should get <code>list of articles</code> on my browser but I get a 404.</p>
  
  <p>I don't have this problem if I put the grouped routes in <code>public/index.php</code> but I don't want to clutter this index as in time I have <strong>more modules</strong> to add in. I prefer splitting the routes into <strong>different</strong> indexes. </p>
  
  <p>So is it possible to <strong>split</strong> the grouped routes into different index.php in <strong>different locations</strong> (directories).</p>
  
  <p>Or maybe this is not how I should do it in Slim? if so, what is Slim's way for solving this problem?</p>