![]() |
How to load database from url - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: How to load database from url (/showthread.php?tid=36291) |
How to load database from url - El Forum - 11-27-2010 [eluser]pshah.mumbai[/eluser] Let me explain how the application works. - Each company account has its own separate database - Lets assume the company name is "acme" - The database settings (hostname, port, dbname, username, password) is specified in system/application/config/database.php file as a group called "acme" Code: $db['acme']['hostname'] = "localhost"; - The URL is of the format http://sitename/acme, where the "acme" should load the database group settings related to acme. Internally it should automatically load the following database settings : Code: $this->load->database('acme'); - The controllers/action are normally accessible via http://sitename/acme/controller/action. Code: http://sitename/acme/group/new - What is the best way to do this ? (I dont mind modifying the core files if needed). How to load database from url - El Forum - 11-27-2010 [eluser]Matt S.[/eluser] You could extend the base controller class and add a "switch" that runs off of the URI segment in the constructor. Make a new file in: Code: application/libraries/MY_Controller.php And use this code: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); You will have to extend MY_Controller in place of Controller if you wish to use this method: Code: class Acme extends MY_Controller { How to load database from url - El Forum - 11-27-2010 [eluser]pshah.mumbai[/eluser] thanks a lot ! I will think about that. one more thing, how to handle the controllers and views url's and other functions like redirect(), anchor(), etc... How to load database from url - El Forum - 11-27-2010 [eluser]Matt S.[/eluser] I'm a little confused on what you're asking. Could you elaborate on what you mean by "handling" them? How to load database from url - El Forum - 11-27-2010 [eluser]pshah.mumbai[/eluser] If the code does redirect("group/new") it should go to http://sitename/acme/group/new and not http://sitename/group/new Also the controller will be set as "acme" and not "group" How to load database from url - El Forum - 11-27-2010 [eluser]Matt S.[/eluser] You will probably have to add the segment manually into the redirect() function like this: Code: redirect( $this->uri->segment(1) . "/group/new"); That is assuming you are calling the redirect() function from somewhere that has "acme" in the URL. How to load database from url - El Forum - 11-27-2010 [eluser]pshah.mumbai[/eluser] ![]() also what will be the controller, action, parameter names that will be assigned by CI ? |