laravel 检测当前页面是否为 web 根
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27651999/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Detect if current page is the web root
提问by Lovelock
Looking for the simplest way of checking via PHP if the current page is the root '/'
寻找通过 PHP 检查当前页面是否为根目录 '/' 的最简单方法
I only want to show a certain element on the root of my website, but using a blade template and have this certain element in the template for all pages.
我只想在我网站的根目录上显示某个元素,但使用刀片模板并在所有页面的模板中包含此特定元素。
Thanks.
谢谢。
E.g.
例如
<?php
if ($page == $root) {
// show
}
?>
If it helps I am using Laravel 4.2.
如果有帮助,我正在使用 Laravel 4.2。
回答by Suresh Bala
You can also do it quickly the following way
您也可以通过以下方式快速完成
if(Request::is('/')) {
//your code here
}
回答by Grant
Within the Bladetemplating of Laravel, the following would suffice
在Laravel的Blade模板中,以下内容就足够了
@if(Request::is('/'))
// The condition you require
@endif
回答by Joseph Silber
if (Route::getCurrentRoute()->uri() == '/')
{
// You're on the root route
}
回答by pavitran
You can simply try
你可以简单地尝试
if ($_SERVER['REQUEST_URI'] == '/')
if ($_SERVER['REQUEST_URI'] == '/')