php Laravel 5中Application URL的意义是什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31129092/
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
What is the significance of Application URL in laravel 5
提问by echoashu
in Config/app.php
in laravel source, what is the actual use of url
?
在Config/app.php
laravel源码中,实际的用途是url
什么?
It says Application URL to be used by artisan command line tool
, so what should it be actually?
它说 Application URL to be used by artisan command line tool
,那么它实际上应该是什么?
I mean should it be http://mydomainname.com
or should it be /var/www/laravel/
or /var/www/laravel/public
我的意思是应该是http://mydomainname.com
还是应该是/var/www/laravel/
或/var/www/laravel/public
Current Configuration
当前配置
/*
|--------------------------------------------------------------------------
| Application URL
|--------------------------------------------------------------------------
|
| This URL is used by the console to properly generate URLs when using
| the Artisan command line tool. You should set this to the root of
| your application so that it is used when running Artisan tasks.
|
*/
'url' => 'http://localhost/',
Provided my application source is located at /var/www/
directory and laravel public folder is /var/www/laravel/public
And the http://mydomainname.com
is pointed to resolve at /var/www/laravel/public
directory
如果我的应用程序源位于/var/www/
目录中,并且 Laravel 公共文件夹是/var/www/laravel/public
并且http://mydomainname.com
指向在/var/www/laravel/public
目录中解析
Use Case:
用例:
I'll be using laravel schedular
from /app/Console/Kernel.php
which will be dispatching periodic sendMail commands
and that in turn will queue up the mails to be sent in database and queue listner
than will process the queue as normal
我将使用laravel schedular
from /app/Console/Kernel.php
which will be dispatch periodic sendMail commands
,然后将要在数据库中发送的邮件queue listner
排队,然后正常处理队列
Queues are working fine at localhost (my local xamp server) however I am concerned as what should be the url
value in production
队列在 localhost(我的本地 xamp 服务器)上工作正常,但是我担心url
生产中的价值应该是多少
回答by patricus
When a user visits your website, Laravel gets a lot of information it needs about the request from PHP's superglobals ($_SERVER, $_GET, $_POST, etc.). Part of this information is the request URL.
当用户访问您的网站时,Laravel 会从 PHP 的超全局变量($_SERVER、$_GET、$_POST 等)中获取有关请求的大量信息。此信息的一部分是请求 URL。
For example, if you access the request methods url()
or path()
, this information was retrieved via the $_SERVER superglobal:
例如,如果您访问请求方法url()
or path()
,则通过 $_SERVER 超全局检索此信息:
$url = Request::url();
$path = Request::path();
However, artisan, commands, jobs, etc. don't have the benefit of this information. It is not a normal HTTP request coming in from the user, it is a PHP command being run from the command line. Because of this, Laravel needs a way to determine what the url of the application should be. This is where the configuration value comes in.
但是,工匠、命令、工作等无法从这些信息中受益。它不是来自用户的普通 HTTP 请求,而是从命令行运行的 PHP 命令。因此,Laravel 需要一种方法来确定应用程序的 url 应该是什么。这就是配置值的用武之地。
In your example, you plan on sending out emails from a queue. Imagine you need to include a link to a route of your website in one of the emails, so you use the UrlGenerator to get the url for the link (URL::route('route.name')
). Since this code is being run inside a command, and isn't related to any type of HTTP request, the base application url will be picked up from the configuration value you set in config/app.php
.
在您的示例中,您计划从队列中发送电子邮件。想象一下,您需要在其中一封电子邮件中包含指向您网站路线的链接,因此您使用 UrlGenerator 获取链接的 url ( URL::route('route.name')
)。由于此代码在命令中运行,并且与任何类型的 HTTP 请求无关,因此将从您在config/app.php
.
As should hopefully be a little more clear now, the url
value should be set to the http url for your application, not any type of directory path. In your example, it should be http://mydomainname.com
.
希望现在更清楚一点,该url
值应该设置为您的应用程序的 http url,而不是任何类型的目录路径。在您的示例中,它应该是http://mydomainname.com
.
回答by Almazik G
when on production, it should be set to
在生产时,它应该设置为
'url' => 'http://your-live-domain.com',
As you mentioned, it's going to be used by the artisan commands and queues.
正如您所提到的,它将由工匠命令和队列使用。
You can leverage .env
to store your live domain. http://laravel.com/docs/5.1#environment-configuration
您可以利用.env
来存储您的实时域。http://laravel.com/docs/5.1#environment-configuration