如何在Laravel 4中获取@if语句(刀片)中的当前URL?

我正在使用laravel 4.我想使用Laravel的Blade模板引擎在视图中访问@if条件中的当前URL,但我不知道如何去做。

我知道它可以使用像<?php echo URL::current(); ?> <?php echo URL::current(); ?>但在@if刀片语句中不可能。

任何建议?


你可以使用: Request::url()获取当前的URL,这里是一个例子:

@if(Request::url() === 'your url here')
    // code
@endif

Laravel提供了一种方法来查明URL是否匹配模式

if (Request::is('admin/*'))
{
    // code
}

检查相关文档以获取不同的请求信息:http://laravel.com/docs/requests#request-information


您也可以使用Route::current()->getName()来检查您的路由名称。

例如:routes.php

Route::get('test', ['as'=>'testing', function() {
    return View::make('test');
}]);

视图:

@if(Route::current()->getName() == 'testing')
    Hello This is testing
@endif

也许你应该试试这个:

<li class="{{ Request::is('admin/dashboard') ? 'active' : '' }}">Dashboard</li>
链接地址: http://www.djcxy.com/p/53069.html

上一篇: How to get the current URL inside @if statement (blade) in Laravel 4?

下一篇: Getting Invalid argument supplied for foreach() by using &