检测当前页面是否为Web根目录

Lov*_*ock 5 php laravel

如果当前页面是根"/",则寻找通过PHP检查的最简单方法

我只想在我的网站的根目录上显示某个元素,但是使用刀片模板并在模板中为所有页面设置了这个元素.

谢谢.

例如

<?php
  if ($page == $root) {
    // show
  }
?>
Run Code Online (Sandbox Code Playgroud)

如果它有助于我使用Laravel 4.2.

小智 15

您也可以通过以下方式快速完成

if(Request::is('/')) {
 //your code here
}
Run Code Online (Sandbox Code Playgroud)


Gra*_*ant 12

在Laravel 的Blade模板中,以下就足够了

@if(Request::is('/'))
    // The condition you require
@endif
Run Code Online (Sandbox Code Playgroud)


Jos*_*ber 11

if (Route::getCurrentRoute()->uri() == '/')
{
    // You're on the root route
}
Run Code Online (Sandbox Code Playgroud)


pav*_*ran 6

你可以简单地尝试

if ($_SERVER['REQUEST_URI'] == '/')