相对于Laravel 4中的基本URL生成URL [英] Generating url relative to the base url in laravel 4
问题描述
我是Laravel&的新手.现在在L-4上构建一个应用程序,但被卡在一个地方.无法了解如何生成相对于基本url的url.在laravel-3中,我知道这可以通过
I'm new to Laravel & right now building one application on L-4 but got stuck at one place. Can't able to understand how to generate url relative to base url. In laravel-3 i know this can be done by
$url = URL::to('user/profile');
但是,在L-4中,我们如何做到这一点??
But, in L-4 how we can do this.. ?
推荐答案
要生成相对 URL,可以使用URL::route
或URL::action
,因为它们允许传递$absolute
参数默认为true
.因此,例如在使用命名路由时要获取相对URL,可以使用以下代码:
To generate a relative URL, you can use URL::route
or URL::action
as they allow to pass a $absolute
parameter which defaults to true
. So to get a relative URL when using named routes for example, you can use the following:
URL::route('foobar', array(), false)
这将生成一个类似于/foobar
的URL.
This will generate a URL like /foobar
.
这篇关于相对于Laravel 4中的基本URL生成URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!