Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

alternative controller design

#41

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?

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

State: new
Milestone: none
Assigned to: nobody

Activity

  1. Steve Clay
    Steve Clay

    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.

    July 14th, 2010 @ 05:49 PM

  2. Fabrice Luraine
    Fabrice Luraine

    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...
    }
    

    July 15th, 2010 @ 10:18 AM

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.