Skip to content

add 'fall-through' routine in router #28

@csurf

Description

@csurf

currently, a user is forced to manually configure each&every single router->action+params combination in order for sonic to successfully route a request. If a given route is not specified in the routes.php config file, it is completely ignored, even though the requested controller+method do exist.
example:
class main extends controller{
...
public function test(){echo 'test';}
...
}
navigating to '/main/test' fails if this specific route hasnt been explicitly defined in routes.php

It becomes tedious having to manually manage every single route, and becomes a possible point of failure/errors.

So, allow for a 'fallback test' that can load a route from a 'controller+method' combination, assuming that they exist. This can be a user-configurable option; the test can be skipped if the user doesn't want or need the fallback, in which case only the defined routes will be applied.

I thought perhaps this could be applied in Router.php, in the _getMatch() function, somewhere toward the end, after the routes have been processed and before the function 'falls through' to returning 'null' if no match was found.

as a test, I simply 'exploded' the uri string and returned the array, but the problem with this method is that it will try to call the 2nd item in the uri array as a method, and the 'transformation' class will 'trigger a fatal error' instead of 'throwing an exception' if the requested method doesnt exist. The exception is required in order to handle the non-existent, i.e. show the error view and/or return a 404, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions