Routing using lang file

#1
[eluser]Ngulo[/eluser]
Hi all guys,

i'm newbie and i would like to route my urls according to a session param which load in my controllers main lang file,

how can i retrieve this lang file in route.php ?

is it possible?

then i'm trying to route this url: http://localhost/asd/index.php/products/category/85
taking examples from CI ufficial guide but i'm not able to make them works Sad

do i need to remove index.php from urls?

thanks guys

#2
[eluser]pickupman[/eluser]
Can you give an example of what to are trying route from and to? ie. /85/my-shoe-product to products/category/85

#3
[eluser]Ngulo[/eluser]
thanks man for helping me...
so first of all i can't route this link for example:

http://localhost/asd/index.php/products/category/85

to
http://localhost/asd/index.php/asd/asd/85

can you give me an example to how to do in main route.php file to route this link?

then i'm using multilanguage site so i would like to route my urls according to site language but i can't find any how to work on Sad

i created my personal language class which is switching into ,my controllers, main lang file to load inside them according to user session param somenthing like this:


Settings.php (system/application/libraries)
Code:
class Settings {

  
     function setSiteLanguage()
    {
        $CI =& get_instance();
        
        if($CI->session->userdata('lang'))
        {
          $CI->config->config['language'] = $CI->session->userdata('lang');
          $CI->lang->load($CI->session->userdata('lang'));
        }
        else
        {
          $CI->config->config['language'] = "en";
          $CI->lang->load('en','en');
          
        }
        
    }
User.php (controller)
Code:
class User extends Controller {

        function user()
        {
            parent::Controller();
            //set site language
             $this->settings->setSiteLanguage();
            
        }
etc ....

so as you can see i switch a user lang session param to load correct lang file

so, in the end, i can't understand how to route my urls according to site lang (which in my case into session array) Sad

hoping you understand my bad english

thanks

#4
[eluser]Ngulo[/eluser]
i was planning to check $_SESSION param into route.php

then do somenthing like this (into route.php):

Code:
if( $_SESSION['lang'] == en){

$route = array(
  'asd/1'=>'asden/1en'
);
}

if( $_SESSION['lang'] == sp){

$route = array(
  'asd/1'=>'asdsp/1sp'
);
}
etc...


but i'm thinking is not the right solution!? :/

thanks again

#5
[eluser]pickupman[/eluser]
I think you may be making this harder than it is. You should have the same url regardless of language for SEO purposes. The language class will always load the english file if a invalid language is specified. I would load the language file using MY_Controller. If you don't have application/libraries/MY_Controller.php create the file with.
Code:
class MY_Controller extends Controller{

  public function __construct(){
    parent::__construct();

    $language = $this->session->userdata('language');
    $this->load->lang('filename', $language); //set filename to something (maybe based on uri)
  }
}

This will execute for every controller, and you will need to set filename to match a language file. If the language key is not found in the user's session, it will load the English file by default.

#6
[eluser]Ngulo[/eluser]
right man i think it too(i make more difficult then it is) Sad

and in the end what about to route this url:
http://localhost/asd/index.php/products/category/85

to
http://localhost/asd/index.php/asd/asd/85

?

i'm trying using this in route.php:

$route['products/category'] = "asd/asd";

but it doesn't works for me Sad

#7
[eluser]pickupman[/eluser]
Quote:i’m trying using this in route.php:

$route[‘products/category’] = “asd/asd”;

but it doesn’t works for me Sad
Should be:
Code:
$route['products/category/(:num)'] = 'asd/asd/$1'; //this would be invalid to have a controller and method with same name
//or
$route['asd/asd/(:num)'] = 'products/category/$1'; //calls products controller - category method and passes integer as first parameter

#8
[eluser]Ngulo[/eluser]
so i've tryed both:

$route['products/category/(:num)'] = 'controller/function/$1';

or

$route['controller/function/(:num)'] = 'products/category/$1';

but they doesn't works don't know why Sad

maybe need i to set some config parameter?

thanks again man Sad


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.