Dynamic Routes from an Library (?) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Dynamic Routes from an Library (?) (/showthread.php?tid=55857) |
Dynamic Routes from an Library (?) - El Forum - 11-13-2012 [eluser]@MaxG[/eluser] Hey Guys, I have created an library to route things from an database dynamically. Here is the Code(application/libraries/route.php): Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Then in the file(application/config/routes.php): Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I have autoloaded the library. The folowing Error comes: Quote:A PHP Error was encountered Oh.. Iam using HMVC(MX). Would be SO nice, if everyone could help me. Sorry for my bad bad english, iam german and to stupid to learn it :-D Greets Dynamic Routes from an Library (?) - El Forum - 11-13-2012 [eluser]PhilTem[/eluser] You can't use dynamic routing in that way since the routes.php file will be loaded way earlier than any other things. Basically it is run and validated after the CI_Config and CI_Loader class is instantiated. Therefore you can't use your library. Furthermore you're not in an object-scope hence $this is not available. What you want to do is extend CI_Router with MY_Router, load the database and query your routes from the database. That's the only way I can think of real dynamic routing. Dynamic Routes from an Library (?) - El Forum - 11-13-2012 [eluser]@MaxG[/eluser] Heyo, How can I do this? HMVC uses MY_Router already. Greets. Dynamic Routes from an Library (?) - El Forum - 11-13-2012 [eluser]PhilTem[/eluser] HMVC doesn't really supply a functional MY_Router, it does however supply a file called MY_Router to load the MX_Router rather than the CI_Router. You can modify MY_Router in APPPATH . 'core/' to match your needs and to do the library loading (use load_class rather than $this->load->library()) You can find the syntax of load_class in BASEPATH . 'core/Common.php' so you know what it does. Your case is a little harder than getting dynamic routes for the modules but it is feasible just requires a lot of understanding of CI business logic and how all the gears work together |