Laravel - 方法 link_to_route 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16845540/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:50:02  来源:igfitidea点击:

Laravel - Method link_to_route does not exist

laravellaravel-4

提问by Lorenz V.

I get an error when i use HTML::link_to_route, but not when i use HTML::Link Why?

当我使用 HTML::link_to_route 时出现错误,但当我使用 HTML::Link 时不会出现错误 为什么?

{{ HTML::decode(HTML::link_to_route('homepage', '<div class="logo"></div>')) }}

The same for:

同样适用于:

{{ HTML::link_to_route('about', 'WHAT IS IT') }}

The error:

错误:

BadMethodCallException
Method link_to_route does not exist.

Version 4.0.x

版本 4.0.x

回答by Lorenz V.

Fixed it, it seems that the documentation is really out-dated, or that laravel 4.0 is just really new ;)

修复了,看来文档真的过时了,或者laravel 4.0真的很新;)

replaced "link_to_route" with "linkRoute". Found it by looking into the vendor files.

将“link_to_route”替换为“linkRoute”。通过查看供应商文件找到它。

回答by simon

Just FYI, or next searcher

仅供参考,或下一个搜索者

For the latest Release (4.1) the text will be encoded itself. to get the link you have to specify the link manually like this

对于最新版本 (4.1),文本将自行编码。要获取链接,您必须像这样手动指定链接

 <a href="{{ URL::route('homepage') }}"><i class="fa fa-pencil "></i></a>

回答by Pazuzu156

It's must easier to use linkRoute.

使用linkRoute 肯定更容易。

Example: {{ HTML::linkRoute('name-of-route', 'Go to my route') }}

示例:{{ HTML::linkRoute('name-of-route', 'Go to my route') }}

回答by Harry Bosh

If you wanted to use the old way http://laravelcollective.com/docs/5.0/html

如果你想使用旧的方式 http://laravelcollective.com/docs/5.0/html

However this seems to be the new way

然而,这似乎是新的方式

string linkRoute(string $name, string $title = null, array $parameters = array(), array $attributes = array())

http://laravel.com/api/5.0/Illuminate/Html/HtmlBuilder.html#method_link

http://laravel.com/api/5.0/Illuminate/Html/HtmlBuilder.html#method_link

See usage http://laravel-recipes.com/recipes/190/generating-a-html-link-to-a-named-route

查看用法 http://laravel-recipes.com/recipes/190/generating-a-html-link-to-a-named-route