Laravel 5 中未定义的函数 link_to

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

Undefined function link_to in Laravel 5

laravellaravel-5php-5.2

提问by Paul Kitutu

I was trying to create a view in Laravel 5, I used the function link_to to create some html link but to my dismay; I got an error as below:

我试图在 Laravel 5 中创建一个视图,我使用函数 link_to 创建了一些 html 链接,但让我感到沮丧;我收到如下错误:

FatalErrorException Call to undefined function link_to()

FatalErrorException 调用未定义的函数 link_to()

Was this function removed? I know the alternative is to write the actual HTML as <a href='url'>Label</a>but I would prefer to use some function like link_to('url','label');

这个功能去掉了吗?我知道另一种方法是编写实际的 HTML,<a href='url'>Label</a>但我更喜欢使用一些函数,如 link_to('url','label');

回答by crynobone

link_tois actually illuminate/htmlhelpers which you need to add manually using composer require "illuminate/html=~5.0"or convert to use url()instead.

link_to实际上illuminate/html是您需要手动添加 usingcomposer require "illuminate/html=~5.0"或转换为 use 的助手url()

回答by xf3227

There is a method presented in Illuminate\Html\HtmlBuilder.php

Illuminate\Html\HtmlBuilder.php 中有一个方法

/**
 * Generate a HTML link.
 *
 * @param  string  $url
 * @param  string  $title
 * @param  array   $attributes
 * @param  bool    $secure
 * @return string
 */
public function link($url, $title = null, $attributes = array(), $secure = null) { ... }

Instead of using link_to or link_to_*, you can find alternative methods registered in facades. If you set the alias as

除了使用 link_to 或 link_to_*,您还可以找到在 Facades 中注册的替代方法。如果您将别名设置为

'Html'      => 'Illuminate\Html\HtmlFacade'

you can try something like

你可以尝试类似的东西

{!! Html::link('url', 'label') !!}

which will give exactly the same function. Hope this post will be helpful.

这将提供完全相同的功能。希望这篇文章会有所帮助。

回答by Ali Mohammed

There's no link_to function. Use url instead:

没有 link_to 功能。改用 url:

{!! url('path', $task->title) !!}