问题描述
在Laravel 5.0中有一个助手会自动添加http到一个url没有它?这类似于codeigniter的 prep_url
,可以找到。
Is there a helper in Laravel 5.0 that automatically adds http to a url without it? This is similar to codeigniter's prep_url
that could be found here.
推荐答案
否,您可以自行添加。在 composer.json
文件中,在自动加载下添加一个文件键,并指向您的帮助文件例如
No but you can add it yourself. In your composer.json
file add a files key under autoload and point it your helper file e.g.
"autoload": {
"files": [
"app/helpers.php"
]
}
然后使用代码创建 app / helpers.php
https://github.com/bcit-ci/CodeIgniter/blob/master/system/helpers/url_helper.php =nofollow> https://github.com/bcit-ci/CodeIgniter/blob/master /system/helpers/url_helper.php ):
Then create app/helpers.php
with the code (lifted from https://github.com/bcit-ci/CodeIgniter/blob/master/system/helpers/url_helper.php):
<?php
if ( ! function_exists('prep_url'))
{
/**
* Prep URL
*
* Simply adds the http:// part if no scheme is included
*
* @param string the URL
* @return string
*/
function prep_url($str = '')
{
if ($str === 'http://' OR $str === '')
{
return '';
}
$url = parse_url($str);
if ( ! $url OR ! isset($url['scheme']))
{
return 'http://'.$str;
}
return $str;
}
}
现在您已拥有 prep_url
全球可访问!不要忘了运行 composer dump-autoload
。
Now you have prep_url
globally accessible! Don't forget to run a composer dump-autoload
too.
这篇关于Laravel将http添加到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!