Skip to content

Instantly share code, notes, and snippets.

@litzinger
Last active August 29, 2015 13:56
Show Gist options
  • Save litzinger/9251642 to your computer and use it in GitHub Desktop.
Save litzinger/9251642 to your computer and use it in GitHub Desktop.
How to extend EE's new routes feature in an extension hook.
<?php
public function core_template_route($uri_string)
{
ee()->your_lib_or_model->load_routes();
// Rest of your hook processing, if any.
}
public function load_routes()
{
if (version_compare(APP_VER, '2.8', '<'))
{
return;
}
ee()->load->library('template_router');
// Load your routes here from config.php or wherever.
foreach ($routes as $route)
{
// Make sure you have everything first
// $route being your custom route path
// $group_name being the group it is assigned to
// $template_name being the template it is assigned to
if ($route && $group_name && $template_name)
{
$template_route = ee()->template_router->create_route($route);
$route_parsed = $template_route->compile();
ee()->template_router->end_points[$route_parsed] = array(
'template' => $template_name,
'group' => $group_name
);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment