How to get database functionality in core classes |
[eluser]d1a8lo24[/eluser]
Hello everyone, new to the forums they have been a great help when building applications with CI. So I need some help in getting the database to work on the core classes specially in the routing class. Now I know that if you want to use the CI super global all you need to do is call the "get_instance()" that one is very easy and it works find when extending the libraries but not the core classes. Now I know the core classes work a different way because of the way they are being loaded so is it possible to get database functionality at this stage? And what would I need to do to implement it. If someone needs a reason on why I would want the database functionality well, is because I think it will be a lot easier to create dynamic routing by just extending the class and having the database create the array. Now I have everything that I need I just need the database to work at this stage. Thanks in advance.
[eluser]InsiteFX[/eluser]
Code: private $CI; InsiteFX
[eluser]d1a8lo24[/eluser]
That is the first thing that I mention that the get_instance() function to get the super global doesn't work in the "core classes" it works fine in the libraries, but not at this stage because of the way the classes are being loaded. I did find 2 topics after an intensive search one is to load the database manually and the other is to create a controller that will create a routes file with your new routes and then include the file with the config routes. The first approach is kind of what I was looking for but its too much work because of not being able to use the CI database class, the second approach is what I'm using at the moment whenever I create a new page in the application a new routes file is created and as CI's reloads it loads all the new files. Not the best but it works. By the way your code will produce this error in the routes core class. Fatal error: Class 'CI_Controller' not found in C:\wamp\www2\system\core\CodeIgniter.php on line 210 Here is what I have right now taken from the following topic: http://ellislab.com/forums/viewthread/154170/ This is a function in my model Code: function _create_routes() Once the routes file has been created just include the file in your config routes file. Code: $route['default_controller'] = "main"; In my case I use query caching for performance, and i use the cache folder in the system folder to write everything in it from the routes file and any other temporary files. This way I can delete everything when ever I update or create a new page. Just call one function using the file helper and calling the delete_files() function. At this point this is the best approach to dynamic routing and thanks again to neillyons.info for his code sample at: http://ellislab.com/forums/viewthread/154170/
[eluser]InsiteFX[/eluser]
You can look at the Loader.php file and the function database(); This is how CodeIgniter loads then etc. InsiteFX |
Welcome Guest, Not a member yet? Register Sign In |