基于这个问题,我试图用英语和西班牙语翻译Laravel 4.2的路线。
这是我的应用程序/ routes.php代码:
<?php /*Set up locale and locale_prefix if other language is selected*/ if (in_array(Request::segment(1), Config::get('app.web_config.alt_langs'))) { App::setLocale(Request::segment(1)); Config::set('app.web_config.locale_prefix', Request::segment(1)); } foreach(Lang::get('routes') as $k => $v) { Route::pattern($k, $v); } Route::group(array('prefix' => Config::get('app.web_config.locale_prefix')), function() { Route::get('/{revelar_fotos}/',['as' => 'revelado_online', 'uses' => 'WebController@reveladoOnline'], function(){ return 'pages.revelado_online'.App::getLocale(); }); });通过点击链接,我得到这个错误的网址:
http://mywebsite.dev/%7Brevelar_fotos%7D代替:
http://mywebsite.dev/photograph-development
这是我的en / routes.php:
<?php return array( 'revelar_fotos' => 'photograph-development', );这是我的es / routes.php:
<?php return array( 'revelar_fotos' => 'revelado-online', );为什么我返回这个错误?
Based on this question I'm trying to translate routes in Laravel 4.2 in english and spanish.
This is my app/routes.php code:
<?php /*Set up locale and locale_prefix if other language is selected*/ if (in_array(Request::segment(1), Config::get('app.web_config.alt_langs'))) { App::setLocale(Request::segment(1)); Config::set('app.web_config.locale_prefix', Request::segment(1)); } foreach(Lang::get('routes') as $k => $v) { Route::pattern($k, $v); } Route::group(array('prefix' => Config::get('app.web_config.locale_prefix')), function() { Route::get('/{revelar_fotos}/',['as' => 'revelado_online', 'uses' => 'WebController@reveladoOnline'], function(){ return 'pages.revelado_online'.App::getLocale(); }); });By clicking on the link I get this error in the url:
http://mywebsite.dev/%7Brevelar_fotos%7DInstead of:
http://mywebsite.dev/photograph-development
This is my en/routes.php:
<?php return array( 'revelar_fotos' => 'photograph-development', );And this is my es/routes.php:
<?php return array( 'revelar_fotos' => 'revelado-online', );Why I returned this error?
最满意答案
我知道你的问题是与生成的URL http://mywebsite.dev/%7Brevelar_fotos%7D
在这个问题中,你只描述了你如何设置路由处理,这可能工作。 然而,生成链接本身在其他地方完成,并且在那里你还没有完成替换。
你必须生成这样的链接
URL::to(trans("revelar_fotos"));trans("revelar_fotos")会为您提供正确的路径, URL::to()生成完整链接。
I understand that you problem is with generating the URL http://mywebsite.dev/%7Brevelar_fotos%7D
In the question you only described how you did set up the routing handling and this might work. However generating the link itself is done somewhere else and in there you have not done the substitution.
You must be generating the link something like this
URL::to(trans("revelar_fotos"));trans("revelar_fotos") will get you the correct path and URL::to() generates full link.
更多推荐
发布评论