• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Routing in Multilanguage (first segment is ignored)

#1
Question 
How can the first segment of URL, which specifies the language, be ignored in Routes.php?


--- A suggested way that does not work:
$routes->add('{locale}/(:any)', '\App\Controllers\$1::index');

--- A suggested way that does not work:
$routes->get('{locale}/(:any)', '$1::index');


--- A suggested way that does not work:
$routes->setAutoRoute(true, 1); // second parameter as the offset, first segment is ignored.

--- A suggested way that does not work:
$routes->add( '(:segment)/(:segment)/(:segment)/(:any)', '\$2::$3/$4' );
$routes->add( '(:segment)/(:segment)/(:segment)', '\$2::$3' );
$routes->add( '(:segment)/(:segment)', '\$2::index' );
$routes->add( '(:segment)', '\Default::index' );

$routes->add( '(:segment)/(:segment)/(:segment)/(:any)', '\\$2::$3/$4' );
$routes->add( '(:segment)/(:segment)/(:segment)', '\\$2::$3' );
$routes->add( '(:segment)/(:segment)', '\\$2::index' );
$routes->add( '(:segment)', '\\Default::index' );


--- A suggested way that does not work:
$route['^(\w{2})/(.*)'] = function($language, $link) use ($route)
{
return isset($route[$link]) ? $route[$link] : $link;
};
$route['^(\w{2})$'] = $route['default_controller'];
Reply

#2
Why can't I use the dollar sign($1) instead of the control name?
Reply

#3
Please see here for in depth description on why $1 or any other number dosen't work for the first replacement. It thinks $ are a literal string, and not a replacement character.

https://forum.codeigniter.com/thread-770...#pid378068
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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