CodeIgniter Forums
Routes with DB Info - 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: Routes with DB Info (/showthread.php?tid=50785)



Routes with DB Info - El Forum - 04-08-2012

[eluser]co[dezyne][/eluser]
I have been scouring around trying to find some information on what I'm attempting to do, and found only this article offering relative answers - problem is, it's from 2008.

Here's hoping there has been some sort of update on this topic.

My controller 'squad' manages all the functionality of an internal group within the larger community of the CMS. I would like to offer admin the ability to change the verb that refers to this group. Examples of such could be: 'team', 'wing', 'platoon', or even 'dogfood' if it satisfies them.

The problem duely noted in the above thread is the issue I have in needing to rewrite the controller name in the URI: Needing to pull the routing from a database string so site.com/squad becomes the value the administrator sets.

I have been researching this for a few hours now and have even attempted to write an extension of the router, but only got this far:
Code:
class MY_Router extends CI_Router {

  function MY_Router()
    {
        $this->config =& get_config();
        parent::__construct();
    }

}

Browsing the web, I have found many functions inside this custom router, but they appear to be far too broad of use than what I'd simply like to accomplish:
Code:
define('UNIT', $this->get_setting('squad-verb') );
$route[UNIT] = "squad";

Does anybody have any suggestions to an approach?


Routes with DB Info - El Forum - 04-09-2012

[eluser]co[dezyne][/eluser]
Friend of mine found this article and the solution works perfectly. Granted it takes another db request, but that's the price to pay.

config/routes.php
Code:
require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->where('setting_slug', 'squad-term')->get( '_settings' );
$result = $query->result();
$term = lcfirst($result[0]->setting_value);

$route[$term] = "squad";
$route[$term . 's'] = "squads";



Routes with DB Info - El Forum - 08-07-2012

[eluser]Unknown[/eluser]
Hi all, does anybody experience problems with the latest 3.0 develop branch with this technique?

I'm now getting Fatal error: Class 'CI_Controller' not found in system\core\CodeIgniter.php on line 229.

Any help appreciated.
Thanks