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

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

问题描述

我正在使用 Laravel 4.我想在使用 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 语句(刀片)中获取当前 URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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