rsanchez / resource_router

Resource Router for ExpressionEngine
MIT License
48 stars 12 forks source link

Ignore an optional segment #38

Open robsonsobral opened 8 years ago

robsonsobral commented 8 years ago

Hi!

I need to make a website available using two different URLs patterns: domain.com and domain.com/city_code.

My approach currently is to use an index.php and a ny/index.php. I've split my configurations and variables on both index.php files and the config.php. But I still need to update the NGINX configuration file, coding a new location directive for every new city.

Before I lose control of everything, please, is it possible to achieve this using Resource Router?

I tried using the following code, but it doesn't look enough:

$config['resource_router'] = array(
    '(sp)/:any/:any' => function($router, $wildcard_1, $wildcard_2) {
        $router->setTemplate( $wildcard_1.'/'.$wildcard_2 );
        $assign_to_config['global_vars']['cv-city_segment']         = "sp";
        $assign_to_config['site_url'] = '/'.$assign_to_config['global_vars']['cv-city_segment'];
        $assign_to_config['global_vars']['cv-city_ch_blog_id']      = "";
        $assign_to_config['global_vars']['cv-city_ch_events_id']    = "";
        $assign_to_config['global_vars']['cv-city_cat_blog_id']     = "";

        // a different variable, so we can change the city segment easier, if needed
        $assign_to_config['global_vars']['cv-city_code']            = 'sp';
    }
);

Thank you!