Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I separate and group the routes into files and folders? #6

Open
lautiamkok opened this issue Aug 31, 2015 · 2 comments
Open

Comments

@lautiamkok
Copy link

I wonder how can we organise the simple routes below when they get bigger when the app grows.

// Configure your routes
$app->set('routes', function (RouteCollector $r) {
    $r->map('/', null, function () {
        return new Response('Hello, world');
    });

    $r->map('/hello/{name}', null, function ($name) {
        return new Response('Hello, ' . $name . '!');
    });
});

For instance, with Slim framework, I can do this when we have routes to be grouped and stored in different files,

$app = new Slim();
require '../app/routes/session.php';
require '../app/routes/member.php';
require '../app/routes/admin.php';
$app->run();

url: http://www.slimframework.com/2011/09/24/how-to-organize-a-large-slim-framework-application.html

Can this be done with Nice?

@tyler-sommer
Copy link
Member

Nice is not too opinionated on how you do things, so you could definitely do something very similar to your Slim example:

$app->set('routes', function (RouteCollector $r) use ($app) {
    require $app->getRootDir().'/app/routes/session.php';
    require $app->getRootDir().'/app/routes/member.php';
    require $app->getRootDir().'/app/routes/admin.php';
});

Then in, for example, session.php:

# session.php
/** @var Nice\Router\RouteCollector $r */
$r->map(....);
$r->map(....);

However, the Nice docs do have a few points on growing your application and ensuring that future maintenance is not a pain. For example, using controller classes rather than Closure actions, and implementing a custom route collector.

@lautiamkok
Copy link
Author

Thanks for the reply and the links. Glad to know that Nice is so flexible! Well done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants