#41 new
Steve Clay

alternative controller design

Reported by Steve Clay | July 14th, 2010 @ 05:32 PM

Currently Lim loads all controller files on every request, and you have to dispatch for each function.

I made some small mods that changes this so that controller files with function names that follow a convention are auto-routed. E.g. Create "controllers/foo.php" and add a function foo_bar() and you'll now have a working route for /foo/bar (for all methods). If foo_bar_POST() is created, it'll be called for POSTs.

In run():

Don't load the controllers.

In route_find():

If a route is not found, and the URI looks like /wordA/wordB, and controllers/wordA.php exists, require it. Then return a new ad-hoc route that points to one of the functions wordA_wordB_METHOD or wordA_wordB (if one exists).

Thoughts?

Comments and changes to this ticket

  • Steve Clay

    Steve Clay July 14th, 2010 @ 05:49 PM

    Another option would be to autoload only the controller file that matches the first word in the URI. This could be done in run() directly before the call to route_find(), so that dispatch* functions could be placed in the controller files.

    Both these options would make controllers more re-usable, and load fewer files per request.

  • Fabrice Luraine

    Fabrice Luraine July 15th, 2010 @ 10:18 AM

    About loading the controller file that matches only the first word in URI, it can be done by defining your own autoload_controller function.

    function autoload_controller($callback)
    {
      $uri = request_uri();
      // ... find first word in uri
      // then load the matching controller
    }
    

    I like the idea you illustrate before, some kind of default routes for a resource. But I think this should be left optionnal, keeping Limonade more versatile and not as opiniated.
    Perhaps by defining a user definable function default_routes called in route_find if no route found:

    function default_routes($method, $path)
    {
      // try checking a controller file foo.php...
      // return false or a route array...
    }
    

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Limonade is a PHP micro-framework.

People watching this ticket

Attachments

Pages