[英]URL helper functions within an Artisan command return empty base URL
When I call any of the url helper functions, eg 当我调用任何url辅助函数时,例如
URL::asset('foo/bar')
from within a command the base URL is an empty string, and the url returned is 在命令中,基本URL是一个空字符串,返回的URL是
http://:/foo/bar
I am running the command by calling 我正在通过调用来运行命令
php artisan myproject:MyCommand
from a command line. 从命令行。 Where MyCommand is a class that extends Illuminate\\Console\\Command
其中MyCommand是扩展Illuminate \\ Console \\ Command的类
I have set my url in config/app.php but I only get a fully qualified url when I run from an HTTP Request 我已经在config / app.php中设置了我的网址,但是当我从HTTP请求运行时,我只会获得完全限定的网址
I am using Laravel Framework version 4.1.24 我正在使用Laravel Framework版本4.1.24
Where did you get URL::asset('')
from? 您从哪里获得
URL::asset('')
? I don't see it mentioned on the documentation 我没有在文档中看到它
Try this instead: 尝试以下方法:
URL::to('foo/bar')
Found the issue. 找到了问题。
My artisan file was missing this line 我的工匠档案缺少这行
$app->setRequestForConsoleEnvironment(); $ app-> setRequestForConsoleEnvironment();
The file I had was an older version. 我拥有的文件是较旧的版本。 This line was added Oct 25, 2013
此行于2013年10月25日添加
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.