我尝试使用slim框架制作自己的多通道应用程序。我为所有语言生成了路由组,其中包含所有标准应用程序路由,如下所示:
$this->app->group($base_folder, function () use ( $base_folder ) {
include 'includes.php';
$availableLangs = explode(",", USE_MULTILINGUAGES);
if(strlen($availableLangs['0']) > 0){
foreach($availableLangs as $availableLang) {
$this->app->group('/'.$availableLang, function () {
include 'includes.php';
});
}
}
});
我的文件include.php包含我的标准路线,如下所示:
//Redirect to Home
$this->app->map('/', function () {
echo '/'.'<br/>';
$this->app->redirect('home');
})->via('GET');
//Homepage
$this->app->map('/home', function () {
$data = new Admin'GetController( 'home' );
$data->send("Home/home.template.html");
})->via('GET');
//Others
require 'Routes/Login.php';
require 'Routes/Logout.php';
require 'Routes/Users.php';
生成的路线很好,当我显示它时:
project/
project/en
project/fr
project/home
project/en/home
project/fr/home
等等。。。
但当我在浏览器中尝试时,只有标准的才有效(项目/和项目/主页)。带有/fr或/en的自定义转到$this->app->notFound
- 为什么它不起作用
- 有更好的方法吗
从url中提取lang时,我正在重写Slim变量['PATH_INFO']。这就是为什么它不起作用。所以它现在运行得很好,但我仍然有兴趣知道是否有更好的方法可以在纤薄的应用程序中添加多车道。
使用完整的资源
- http://nesbot.com/2012/6/26/multilingual-site-using-slim
- https://fiberonofiber.wordpress.com/2014/02/13/slim-php-multi-language-urls/
- https://github.com/SimoTod/slim-multilanguage