Welcome Guest, Not a member yet? Register   Sign In
Routing Catch 22
#1

[eluser]mikedfunk[/eluser]
I'm working on a CMS and I'm trying to do some dynamic routing but I find that neither solution will do the trick. routes.php doesn't have access to models while _remap() can only send to methods within the current controller. I need access to models and to be able to route to controller/method. Any ideas on how to do that?

The reason I need this is because for dynamic public views such as events I have a row in the pages table which has 'is_events_page' set to true. This way the CMS admin can set the events page url to whatever they want and they can further customize the page. So in routing I need to get the url of the events page via the model, compare the passed url, if true send to the events function instead of the page function.
#2

[eluser]WanWizard[/eluser]
Short answer: you can't.

This has been discussed numerous times on this forum. The routing decision is taken way before CI is fully up and running (which doesn't happen until the controller is called), and the database is accessable.

Several options have been proposed. One is to have your routing in a database, and after an update in the admin interface, generate a new routes.php from the info in your database. Some use redirects, catch all 'unknown' requests with the default controller which then does a lookup and a redirect, which then need to be processed by the routes. This doesn't work when your URI's are completly dynamic.

We at ExiteCMS went a different route. We don't use routes at all, we route all requests to the default controller. The default controller has access to all CI resources. It will process the request using a "virtual" website folder tree build in the database, and based on that result load the corresponding controller(s). To do that we've extended the loader class to be able to have one controller load another.
#3

[eluser]mikedfunk[/eluser]
Interesting. I'm going through your CMS_Loader class and got it working in my CMS context. I had to change
Code:
isset($this->module_context)
to
Code:
!empty($this->module_context)
because the module_context property is set to array() at the beginning which defines it as set. Since my views were not in a module context they weren't getting loaded. Bug?
#4

[eluser]WanWizard[/eluser]
Looks like you found an old piece of code?

I found this code in a revision from three months ago, when we were still using 1.7.2 code. Since then, we've migrated to 2.0, and have completely rewritten the loader class extension (using the new 2.0 packages).




Theme © iAndrew 2016 - Forum software by © MyBB