How can Phalcon separate /public/index.php code to several php files?

When I doing Micro application, all business logic will be writen in /public/index.php. So the index.php will be very long. How can I separate this long file to several php files?

Use classes or include()



130
edited May '14

Here is what I did:

// public/index.php

if (isset($_GET['_url']) && preg_match('#/([a-z]+)#', $_GET['_url'], $matches)) {
    $filepath = __DIR__ . '/../controllers/' . $matches[1] . '.php';
    if (file_exists($filepath)) {
        require $filepath;
    }
}

// controllers/blog.php

$app->get('/blog.html', function () use ($app) {
  // ...
});