[英]passing parameter to URL::to() method of laravel
I want a link in my html file to point to a URL
using the URL::to()
method. 我希望我的html文件中的链接使用
URL::to()
方法指向一个URL
。 But I also want that, when someone clicks the link I can send some data with it. 但是我也希望这样,当有人单击链接时,我可以发送一些数据。 So, how can I pass parameter to
URL::to()
method of laravel. 因此,如何将参数传递给laravel的
URL::to()
方法。 For ex.- 对于-
I want to do this- 我想做这个-
URL::to('search')->with('x','12');
And I will place this method in my html file within ' {{}}
' as per Laravel docs. 根据Laravel文档,我将把该方法放在html文件中的
{{}}
。 I have searched the net as well as laravel docs but couldn't find anything for this specific problem. 我已经在网上搜索了laravel文档,但找不到任何针对此特定问题的信息。 And, I am not able to find any other way out to this.
而且,我找不到其他解决方法。
Update : Resolved. 更新 : 已解决。 URL::route() did the work.
URL :: route()完成了工作。
You may use: 您可以使用:
link_to('foo/bar', $title, $attributes = array(), $secure = null);
For example: 例如:
{{ link_to('foo/bar/' . $param1, 'Goto Foo') }}
Or this way: 或者这样:
{{ link_to("foo/bar/$param1", 'Goto Foo') }}
Check the documentation . 检查文档 。 Also, if you use
route
it would be easy to pass parameters in a separate array, {{ route('routename', array('username' => $user->username))
. 另外,如果使用
route
则很容易在单独的数组中传递参数, {{ route('routename', array('username' => $user->username))
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.