Beginning in BigTree 5.0, module classes are able to register routes with the main CMS route registry that will control the way certain URL routes are delivered. The base BigTreeModule class now includes a static property called $RouteRegistry that is extended in your module's custom class. The $RouteRegistry property is an array of arrays with the following keys:
- "type" — Either "admin" for matching a route inside your admin interface, "public" for matching a public-facing route, or "template" for hooking additional routes passed to a routed template.
- "pattern" — A routing pattern based on the Slim Framework's routing
- "template" — If the "type" entered is "template", the template ID that is being hooked
- "file" — The location of the file to include when the route is hit. If the "type" is "template" this file path is relative to the routed template's directory, otherwise it is relative to SERVER_ROOT.
- "function" — A function to run when the route is hit (overrides "file").
Routing Patterns
BigTree 5.0+ uses the Slim Framework's routing patterns.
For example, if you choose "/my-module/test/:route:" as your pattern, when a user visits http://website.com/admin/my-module/test/my-test/ they will be "caught" by your module's routing and directed to whatever file or function you define. Each route will then be passed to your function or file as a variable. In the example pattern "route" is what is being caught as the final parameter and therefore $route will be available in your function or file. You can define multiple parameters in different locations which makes the routing in BigTree 5 much more versatile. For example, "/news/:route:/images/:index:" will look for hits to http://website.com/news/test-article/images/5/ and store "test-article" in $route and "5" in $index.
Drawing the Page
If you're using the "admin" type for your routing you will be drawn within admin layout just like any page in /admin/modules/ or /admin/pages/. If you're using "template" or "public" the included file or function output will be included in the layout specified in $bigtree["layout"] just like a normal template. If you are including a file from within a directory that normally would include _header.php and _footer.php files, the router behaves just as you would expect.