如何在Laravel 4的@if语句(Blade)中获取当前URL? [英] How to Get the Current URL Inside @if Statement (Blade) in Laravel 4?

查看:363
本文介绍了如何在Laravel 4的@if语句(Blade)中获取当前URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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