使用URL :: action()时如何更改域 [英] How do I change the domain when using URL::action()
问题描述
我正在尝试复制Laravel 3中可用的内容.我希望能够为路由指定备用域名.例如,我有一条使用此代码生成以下内容的路由:
I am trying to duplicate something that was available in Laravel 3. I want to be able to specify an alternate domain name for a route. For example, I have a route that produces the following with this code:
URL::action('DashboardController@something')
// Produces: http://somedomain.com/dashboard/something
我希望能够指定其他域.这曾经是config/application.php文件中的"url".在L4中不再有效.
I want to be able to specify a different domain. This used to be in the config/application.php file as 'url'. This no longer works in L4.
是否有一种方法可以指定在构造URL时要使用的基本URL?
Is there a way to specify a base url to use whenever a URL is being constructed?
推荐答案
Laravel 4使用HTTP请求标头字段Host
中指定的域,例如Host: http://foo.dev
.
Laravel 4 uses the Domain specified in the HTTP Request Header Field Host
, e.g. Host: http://foo.dev
.
如果您要使用其他域名,请尝试以下操作:
If you want a different domain name, try something like this:
Route::group(array('domain' => 'bar.dev'), function()
{
Route::controller('home', 'HomeController');
});
现在URL::action('HomeController@getWelcome');
返回https://bar.dev/home/welcome
而不是https://foo.dev/home/welcome
这篇关于使用URL :: action()时如何更改域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!