Welcome Guest, Not a member yet? Register   Sign In
Routing using lang file

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

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

thanks man for helping me...
so first of all i can't route this link for example:



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)
class Settings {

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

        function user()
            //set site language
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


i was planning to check $_SESSION param into route.php

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

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

$route = array(

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

$route = array(

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

thanks again

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.
class MY_Controller extends Controller{

  public function __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.

right man i think it too(i make more difficult then it is) Sad

and in the end what about to route this url:



i'm trying using this in route.php:

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

but it doesn't works for me Sad

Quote:i’m trying using this in route.php:

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

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

so i've tryed both:

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


$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

Theme © iAndrew 2016 - Forum software by © MyBB