CodeIgniter Forums
routes and multi-language - 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 and multi-language (/showthread.php?tid=34525)



routes and multi-language - El Forum - 10-02-2010

[eluser]hydevision[/eluser]
Hello,

I've just started using codeigniter and I've got a question about routing. I've added an config item called multi_lang which can be TRUE or FALSE. When TRUE a language identifier get's added to my url, like this http://www.sitename.com/eng/blog .

I've got two controllers, one for frontend (page) and one for admin.

Now I've got the following routes:

Code:
$route['beheer'] = 'admin';
$route['beheer/:any'] = 'admin';
$route['beheer/:any/:any'] = 'admin';
$route['beheer/:any/:any/:any'] = 'admin';
$route[':any'] = 'page';
$route[':any/:any'] = 'page';
$route[':any/:any/:any'] = 'page';
$route[':any/:any/:any/:any'] = 'page';
$route['default_controller'] = 'page';
$route['(\w{2})/(.*)'] = '$2';
$route['(\w{2})'] = $route['default_controller'];
$route['scaffolding_trigger'] = "";

When multi_lang = FALSE I can reach the admin section. But when I set it TRUE all request are transferred to the page controller. Anybody an idea what routes to set so I can reach the admin controller with multi_lang = TRUE?


routes and multi-language - El Forum - 10-02-2010

[eluser]WanWizard[/eluser]
Most multi language solutions that work this way implement some hook code to strip the language code from the URI so the extra segment doesn't affect routing. Do a search for multi-language here, you probably find some solutions...

Also, you can change
Code:
$route['beheer'] = 'admin';
$route['beheer/:any'] = 'admin';
$route['beheer/:any/:any'] = 'admin';
$route['beheer/:any/:any/:any'] = 'admin';

to
Code:
$route['beheer(.*)'] = 'admin';

Makes your routes a lot more readable.


routes and multi-language - El Forum - 10-03-2010

[eluser]hydevision[/eluser]
Thx WanWizard!

I already thought the routes could be better.

Do you also mean it isn't in the routes but in the multi-language setup?

Anyway, I'll try out your suggestion and start reading threads about multi-language.

Cheers and thanks again!

Bart


routes and multi-language - El Forum - 10-03-2010

[eluser]hydevision[/eluser]
If anybody is interested. I've come up with the following solution:

The path to my admin section is set in config.php. Now I include the MY_Language library and I've added some checks in top of the library. If the checks are met than it will load the library and adds the language abbr to the url.

Like this:

Code:
class MY_Language extends CI_Language {
    
    function MY_Language()
    {
        global $RTR;
        
        $index_page        = $RTR->config->item('index_page');
        $lang_uri_abbr    = $RTR->config->item('lang_uri_abbr');
        $lang_db_abbr = $RTR->config->item('lang_db_abbr');
        $multi_lang = $RTR->config->item('multi_lang');
        $admin_path = $RTR->config->item('admin_path');
        $admin_uri = $RTR->uri->segment(1, '');
        
        if ($multi_lang == TRUE AND $admin_path != $admin_uri)
        {
        //-> continue function
        }