如何为Laravel 4路线设置多个模式?

如何为Laravel 4路线设置多个模式?,laravel,laravel-4,Laravel,Laravel 4,我在Laravel 3的一个项目中有一条路线: Route::get(array('/Home', '/'.rawurlencode ('خانه')), function() { return View::make('home.index'); }); 它工作正常,直到我决定将它迁移到Laravel 4。现在在Laravel 4中,我得到了这个错误: preg\u match\u all()要求参数2为字符串,数组给定 有没有其他方法可以为Laravel 4 route设置多个模式?

我在Laravel 3的一个项目中有一条路线:

Route::get(array('/Home', '/'.rawurlencode ('خانه')), function()
{
    return View::make('home.index');
});
它工作正常,直到我决定将它迁移到Laravel 4。现在在Laravel 4中,我得到了这个错误:

preg\u match\u all()要求参数2为字符串,数组给定


有没有其他方法可以为Laravel 4 route设置多个模式?

您可以在route中使用正则表达式,所以可能类似这样

Route::get('(Home|' . rawurlencode('خانه') . ')', function ()
{
    return View::make('home.index');
});

如果这不起作用,我可能会定义两条路线,因为闭包非常简单。即使它更复杂,您也可以将其移动到控制器并以相同的控制器方法指向两条路由。

您可以在路由中使用正则表达式,因此可能类似于这样

Route::get('(Home|' . rawurlencode('خانه') . ')', function ()
{
    return View::make('home.index');
});

如果这不起作用,我可能会定义两条路线,因为闭包非常简单。即使它更复杂,您也可以将其移动到控制器并以相同的控制器方法指向两条路由。

您可以使用
实现这一点,其中
使用您的路由

所以如果你的路线是

Route::get('{home}', function()
{
    return View::make('home.index');
})->where('خانه', '(home)?');
您可以使用

http://localhost/laravel/home
http://localhost/laravel/خانه
这里是
http://localhost/laravel/
应替换为您的

使用
regex
是最好的方法

Route::get('{home}', function()
{
    return View::make('home.index');
})->where('home', '(home|خانه)');
这只会匹配

http://localhost/laravel/home
http://localhost/laravel/خانه

您可以使用
where
和您的路线来实现这一点

所以如果你的路线是

Route::get('{home}', function()
{
    return View::make('home.index');
})->where('خانه', '(home)?');
您可以使用

http://localhost/laravel/home
http://localhost/laravel/خانه
这里是
http://localhost/laravel/
应替换为您的

使用
regex
是最好的方法

Route::get('{home}', function()
{
    return View::make('home.index');
})->where('home', '(home|خانه)');
这只会匹配

http://localhost/laravel/home
http://localhost/laravel/خانه

谢谢你,伙计。。。工作起来很有魅力!:)谢谢你,伙计。。。工作起来很有魅力!:)谢谢你,伙计!不幸的是,它没有工作。。。但Devo的解决方案很棒……:)谢谢你,伙计!不幸的是,它没有工作。。。但Devo的解决方案很棒……:)