问题描述
我正在使用Laravel4.我想使用Laravel的Blade模板引擎在视图中的@if
条件内访问当前URL,但我不知道该怎么做.
I am using Laravel 4. I would like to access the current URL inside an @if
condition in a view using the Laravel's Blade templating engine but I don't know how to do it.
我知道可以使用<?php echo URL::current(); ?>
之类的方法来完成此操作,但是在@if
刀片语句中是不可能的.
I know that it can be done using something like <?php echo URL::current(); ?>
but It's not possible inside an @if
blade statement.
有什么建议吗?
推荐答案
您可以使用:Request::url()
获取当前URL,下面是一个示例:
You can use: Request::url()
to obtain the current URL, here is an example:
@if(Request::url() === 'your url here')
// code
@endif
Laravel提供了一种方法来找出URL是否与模式匹配
Laravel offers a method to find out, whether the URL matches a pattern or not
if (Request::is('admin/*'))
{
// code
}
查看相关文档以获取不同的请求信息: http://laravel.com/docs/requests#request-information
Check the related documentation to obtain different request information: http://laravel.com/docs/requests#request-information
这篇关于如何在Laravel 4的@if语句(Blade)中获取当前URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!