Laravel 5 Laravel 5使用图标/html链接到
有人知道如何将HTML放入link_to_*helper函数的$title参数中吗 我一直在谷歌上搜索,直接在网上找到了一些关于它的话题,但这里只有一些建议:Laravel 5 Laravel 5使用图标/html链接到,laravel-5,Laravel 5,有人知道如何将HTML放入link_to_*helper函数的$title参数中吗 我一直在谷歌上搜索,直接在网上找到了一些关于它的话题,但这里只有一些建议: 制作您自己的助手(尝试过,但最终我使用link_to_*或App::make('html')->linkRoute(…);示例 在视图内生成链接并使用URL facade 使用HTML facade对视图中的链接进行编码(我认为这是不安全的,不知道为什么感觉这是错误的) 为了让自己清楚,我在问如何让1.建议有效?(我尝试了helpers,
App::make('html')->linkRoute(…);
示例链接到路径(“some.route”,“这是带有图标的标题”);
和我制作的帮助器(下面的代码)。其中$icon='';
两个(我自己的助手或L5助手)都输出相同的结果:
- 在浏览器中可见:
name
- html代码:
问题是您正在使用
linkRoute
方法,该方法最终会对传递的标题字符串调用htmlentities
。您必须自己构建HTML以使其正常工作。下面是一个通用示例(为了生成图标链接,请随意对其进行更多优化)
函数链接到路由html($name,$html,$parameters=array(),$attributes=array())
{
$url=路由($name,$parameters);
返回“”;
}
然后你这样称呼它:
link_to_route_html('some.route', 'This is title with icon <i class="icon"></i>');
link_to_route_html('some.route','This is title with icon');
这些几乎都是您的选项。您的问题到底是什么?坦率地说,所有的建议都是“错误的”,我只是想发送HTML(在我的例子中是图标)对于为我创造一切的方法。1.建议不起作用,我想让它发挥作用,这是我的问题。2.建议是无用的,因为会有太多重复的代码。3.建议的原因在括号中。@lukasgeiter看到我的编辑,谢谢。谢谢,这正是我要找的。最新的link_to()helper也将$secure作为第四个参数,将$escape作为第五个参数。将escape设置为false,我可以将html作为标题。
if ( ! function_exists('link_to_route_icon'))
{
function link_to_route_icon($name, $title = null, $icon = null, $parameters = array(), $attributes = array())
{
$url = route($name, $parameters);
return '<a href="' . $url . '"' . app('html')->attributes($attributes) . '>' . htmlentities($title) . ' ' . $icon . '</a>';
}
}
"psr-4": {
"App\\": "app/"
},
"files": [
"app/Helpers.php"
]
link_to_route_html('some.route', 'This is title with icon <i class="icon"></i>');