Welcome Guest, Not a member yet? Register   Sign In
Routing in Multilanguage (first segment is ignored)
#1
Question 
(This post was last modified: 07-25-2020, 12:13 AM by yamahdico.)

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




Theme © iAndrew 2016 - Forum software by © MyBB