0

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 I am encountering is needing to pull the routing from a database string so site.com/squad becomes the value the administrator sets. However. one cannot do this without a) hacking the core or b) extending the CI_Router.

I have started the extension, but only got this far:

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

All I would like to accomplish is:

define('UNIT', $this->get_setting('squad-term'));
$route[UNIT] = "squad"; 

Does anybody have an approach to this?

0

2 Answers 2

1

The way I usually do this is to prepend a string (ex: squad_) to the segment which you can then match with a regex in routes.php

site.com/squad_team
site.com/squad_squad
site.com/squad_dogfood

Or a bit cleaner, add another 'level' which you can then match in routes.php via $route['s/(:any)']

site.com/s/team
site.com/s/squad
site.com/s/food

Having said that, I'm not sure why you

need to rewrite the squad controller's name

?

Sign up to request clarification or add additional context in comments.

1 Comment

Doing this still requires the route search to be dynamic. Allow me to be more clear. The functionality for group actions (manage users, community walls, messages, news, etc) is handled by the controller squad. Since not every installing admin wants to call the divisions of his community 'squads', i set up a method to change the verb, ie to team. It is quite silly to have a controller that handles the management of your 'teams' to be called 'squad', don't you think? Therefore, i want to conditionally route the controller based on the verb assigned in the database.
1

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

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";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.