laravel 5中Application URL的意义是什么 [英] What is the significance of Application URL in laravel 5

查看:173
本文介绍了laravel 5中Application URL的意义是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

url的实际用法是什么?

它说artisan command line tool要使用的应用程序URL,那么它实际上应该是什么?

It says Application URL to be used by artisan command line tool , so what should it be actually?

我的意思是应该是http://mydomainname.com还是/var/www/laravel//var/www/laravel/public

I mean should it be http://mydomainname.com or should it be /var/www/laravel/ or /var/www/laravel/public

当前配置

/*
|--------------------------------------------------------------------------
| 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/',

提供我的应用程序源位于/var/www/目录中,而laravel公用文件夹为/var/www/laravel/public 并且http://mydomainname.com指向解析在/var/www/laravel/public目录

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

用例:

我将使用/app/Console/Kernel.php中的laravel schedular,这将分派periodic sendMail commands,这反过来将使要发送到数据库中的邮件排队,而queue listner则比照常处理队列

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

队列在localhost(我的本地xamp服务器)上工作正常,但是我担心生产中的url值应该是什么

Queues are working fine at localhost (my local xamp server) however I am concerned as what should be the url value in production

推荐答案

当用户访问您的网站时,Laravel从PHP的超全局变量($ _SERVER,$ _ GET,$ _ POST等)获取了大量有关请求的信息. ).此信息的一部分是请求URL.

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.

例如,如果您访问请求方法url()path(),则此信息是通过$ _SERVER超全局变量检索的:

For example, if you access the request methods url() or path(), this information was retrieved via the $_SERVER superglobal:

$url = Request::url();
$path = Request::path();

但是,工匠,命令,作业等没有从此信息中受益.这不是来自用户的普通HTTP请求,而是从命令行运行的PHP命令.因此,Laravel需要一种方法来确定应用程序的URL应该是什么.这是配置值的来源.

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.

在您的示例中,您计划从队列中发送电子邮件.想象一下,您需要在一封电子邮件中包含指向您的网站路线的链接,因此您使用UrlGenerator获取链接的URL(URL::route('route.name')).由于此代码是在命令内运行的,并且与任何类型的HTTP请求都不相关,因此将从您在config/app.php中设置的配置值中提取基本应用程序的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.

现在希望应该更加清楚了,应该将url值设置为您的应用程序的http url,而不是任何类型的目录路径.在您的示例中,它应该为http://mydomainname.com.

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.

这篇关于laravel 5中Application URL的意义是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆