'(:section_uri)/(:page_uri)' => 'web/index',
// $module is retrieved from database
$widget = $module.'/web/'.$this->param('page_uri');
$this->response = Request::factory($widget, false)->execute()->response();
// reset the router so only module routes are used \Router::routes = array(); // route the widget request $this->response = Request::factory($widget)->execute()->response();
Maybe it's better if I give you some more background information, to what my actual situation is. Maybe there is a smarter way to handle this.
Ok, I'm re-building an existing CMS application to Fuel. The basic idea of the URLs within the CMS is that the first segment references to the 'section' and the rest of the segments make up the 'page url', within that section. The section segment can be whatever the user chooses (e.g. english, website, test etc.) and in the database is stored which module-type the section is (e.g. website, blog, forum etc.).
So what I have so far is 1 main controller that handles all the requests. It does a lookup in the database which module we are handling now, and then should hand the control over to the appropriate module. Then to keep my application modular I figured it makes sense to have the module handle the specific routing from that point on (e.g. a 'reply' segment for a forum-module would have a different route).
So far I'm trying different approaches with invoking the module-controller from my main controller (static calls and HMVC requests), but it doesn't work all that well yet.
I hope you understand where I'm going with this, and would appreciate your view on it!
Thanks a lot in advance! Harro Verton wrote on Tuesday 28th of June 2011:Should be \Routes::$routes. It's a static class property.

Harro Verton wrote on Tuesday 28th of June 2011:I do something similar, but my modules don't produce pages, only widgets. So by front controller sets up the theme, fetches the defined widgets from the database, launches requests for each of the widgets and passes the result on to the theme template.
public static function add_before($path, $options = null)
{
if (is_array($path))
{
foreach ($path as $p => $t)
{
static::add_before($p, $t);
}
return;
}
$name = $path;
if (is_array($options) and array_key_exists('name', $options))
{
$name = $options['name'];
unset($options['name']);
if (count($options) == 1 and ! is_array($options[0]))
{
$options = $options[0];
}
}
$route[$name] = new \Route($path, $options);
static::$routes = array_merge($route, static::$routes);
}
// check if the module has custom routes
if (file_exists($modpath .= 'config/routes.php'))
{
// load and add the routes
\Config::load(\Fuel::load($modpath), 'routes', true); // added true, to force reload
\Router::add_before(\Config::get('routes')); // now calling add_before instead of add
}
// Reverse the file list so that we load the core configs first and // the app can override anything.
Harro Verton wrote on Tuesday 28th of June 2011:Module routes are required to always start with 'modulename/' on the lefthand side. If you have violated that rule, there could be a mixup with your global routes.
It looks like you're new here. If you want to get involved, click one of these buttons!