php Laravel 4 - 刀片模板 - 如何正确链接到路由?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22751866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 - Blade Templating - How to properly Link to Route?
提问by LoveAndHappiness
I want to create a resourceful link with Laravel.
Normally I just use the {{ link_to_route('Yadayadayada.route', 'LinkName', $params }}
我想与 Laravel 创建一个足智多谋的链接。通常我只使用{{ link_to_route('Yadayadayada.route', 'LinkName', $params }}
But in this case I am using a Template with this layout:
但在这种情况下,我使用的是具有这种布局的模板:
<a href="index.html">
<i class="icon-dashboard"></i>
<span class="menu-text"> Dashboard </span>
</a>
That means that inside the anchor tag, is as well a <i>
-Tag and a <span>
-Tag.
Is it possible to use the {{ link_to_route }}
-Method, without having to change the layout of the Template?
这意味着在锚标签内部,还有一个<i>
-Tag 和一个<span>
-Tag。是否可以使用{{ link_to_route }}
-Method ,而不必更改模板的布局?
回答by Joseph Silber
Use URL::route()
to get just a link:
使用URL::route()
得到的只是一个链接:
<a href="{{ URL::route('user/profile/', $params) }}">
<i class="icon-dashboard"></i>
<span class="menu-text"> Dashboard </span>
</a>
回答by Alejandro Silva
If you Route use a Closure, you can use URL::to()
, like this
如果您路由使用闭包,则可以URL::to()
像这样使用
<a href="{{ URL::to('home/otherpage', $params) }}">
<i class="icon-dashboard"></i>
<span class="menu-text"> Dashboard </span>
</a>
As @orrd sugested, in general terms is better to use named routes, so it can be easily change the URL later:
正如@orrd 建议的那样,一般而言,使用命名路由更好,因此以后可以轻松更改 URL:
<a href="{{ URL::route('routeName', $params) }}">
<i class="icon-dashboard"></i>
<span class="menu-text"> Dashboard </span>
</a>
回答by Hamid Naghipour
if you define Route name you can use that in your blade :
如果您定义路线名称,您可以在您的刀片中使用它:
Route::get('/admin/transfer/forms-list', [
'as' => 'transfer.formsList',
'uses' => 'Website\TransferController@IndexTransferForms'
]);
now you can use that in your blade like this :
现在你可以像这样在你的刀片中使用它:
<a href="{{URL::route('transfer.formsList')}}" type="submit">
discard</a>
回答by Govind Samrow
There are no of ways to use route in blade:
在刀片中没有使用路由的方法:
1. Use Action
1. 使用动作
{{URL::action('DemoController@index',$params)}}
2. Use Route
2. 使用路线
{{ URL::route('route/', $params) }}
3. Use URL to
3.使用网址
{{ URL::to('route/name', $params)) }}
回答by Sam Prasanna
{{ link_to_route('dashboard', 'Dashboard', '', array('class'=>'body')) }}
{{ link_to_route('dashboard', 'Dashboard', '', array('class'=>'body')) }}
回答by Papa Kent
Use URL::route() to get just a link:
使用 URL::route() 获取链接:
<a href="{{ URL::route('user/profile/', $params) }}">
<i class="icon-dashboard"></i>
<span class="menu-text"> Dashboard </span>
</a>