我想在我的网站中添加语言参数链接。
类似的东西:
http://www.example.com/en/home
这是我的routes.php文件:
use Cake\Core\Plugin;
use Cake\Routing\Router;
use Cake\ORM\TableRegistry;
use Cake\Core\Configure;
Router::defaultRouteClass('Route');
Router::addUrlFilter(function ($params, $request) {
if (isset($request->params['language']) && !isset($params['language'])) {
$params['language'] = $request->params['language'];
}
else{
$params['language'] = 'en';
}
return $params;
});
Router::scope('/', function ($routes) {
$lang = 'en|it|fr';
$routes->connect('/', ['language' => 'en', 'controller' => 'Pages', 'action' => 'index', 'index']);
$routes->connect(
'/:language/:controller',
['action' => 'index'],
['language' => $lang]
);
$routes->connect(
'/:language/:controller/:action',
['language' => $lang]
);
$routes->fallbacks('InflectedRoute');
});
Plugin::routes();
问题是:
当我写这个网址时:http://example.com/admins
它正确地成为http://example.com/en/admins/index
当我写这个网址时:http://example.com/admins/index
它变为http://example.com/admins/index
不正确
我该如何解决?