Getting the super-object $CI in Router class? |
[eluser]flokky[/eluser]
Hello everyone, I want to load a database model in the Router class, since I'm overriding some of its behaviour, but I'm stuck in loading the super-object $CI using Code: //Get the CI super object instance I'm getting this error.. Code: Fatal error: Call to undefined function get_instance() in (...)\Router.php Anyone any idea how I can fix this? Thanks!
[eluser]xwero[/eluser]
The router class is loaded before the CI instance is created so you can't load a model normally.
[eluser]flokky[/eluser]
I really would like to load the database model and do a query on the database (instead of reading the routes from the routes.php file). What else are my options? There has to be a way, right?
[eluser]xwero[/eluser]
I wonder why you need routes from the database? They are not going to change on a daily base and there not going to be many.
[eluser]flokky[/eluser]
I would like to 'bundle' all my texts on the website, but refuse to create different pages (which basically are all the same). So I've created a generic controller which fetches the URI (e.g. http://www.host.com/index.php/contact_us) and using the routes.php to find that 'contact_us' is mapped to that 'generic' controller, where the appropriate text is fetched and forwarded to the view. Now I would like to switch from file to database... Code: Database structure: If you have a better idea to do this, please let me know.
[eluser]xwero[/eluser]
If i understand you now your route is something like Code: $route['(.+)'] = 'controller/method/$1'; Code: class Some_Controller extends Controller
[eluser]flokky[/eluser]
Not quite. I'll just post my code over here. I think you'll faster understand what I mean. The controller: Code: class Handler extends Public_Controller { The view: Code: <div class="spanner"> The routes.php file: (handler is the name of the module using Matchbox and handler is also the name of the controller) Code: $route['contact_us'] = "handler/handler"; Example how this would be in the database (example: URL http://host.com/index.php/about_us was requested): Code: id = 24 Does this makes sense?
[eluser]xwero[/eluser]
you can do Code: $route['contact_us|about_us|thanks'] = "handler/handler";
[eluser]flokky[/eluser]
I want to do it dynamically: and lose the routes.php file, since it's not maintainable that way
[eluser]xwero[/eluser]
What do you mean it's not maintainable that way? If you were talking about user created pages i could understand it better but you are talking about static pages. It would be a bit foolish to alter the router class to make it slower because you want to query the database each time a page loads. |
Welcome Guest, Not a member yet? Register Sign In |