Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为包含的菜单创建if语句_Php - Fatal编程技术网

Php 为包含的菜单创建if语句

Php 为包含的菜单创建if语句,php,Php,我有一个菜单,在我的一个目录中是一致的。比如说, 主页 文件页 照片页 我希望能够在每一页中包含这样的菜单,我就完成了。但是,这次有点不同,因为各个页面生成的链接必须不同,即使目的地相同。以galleries.php页面的链接为例: From the Home page: <a href='galleries.php?id=<?=$id?>'> From the Documents page: <a href='galleries.php?id=<

我有一个菜单,在我的一个目录中是一致的。比如说,

主页 文件页 照片页

我希望能够在每一页中包含这样的菜单,我就完成了。但是,这次有点不同,因为各个页面生成的链接必须不同,即使目的地相同。以galleries.php页面的链接为例:

From the Home page:       <a href='galleries.php?id=<?=$id?>'>
From the Documents page:  <a href='galleries.php?id=<?=$doc[lid]?>'>
From the Photos page:     <a href='galleries.php?id=<?=$photo[lid]?>'>
From the Productss page:  <a href='galleries.php??id=<?=$product[lid]?>'>

从主页:
$\u服务器['REQUEST\u URI']
可以为您提供当前所在的页面,您可以使用它来确定应该链接到哪里

例如:

function displayGalleryId($lid) {
    $uri = $_SERVER['REQUEST_URI'];
    switch ($uri) {
        case '/home.php':
            $link = $id;
            break;

        case '/documents.php':
            $link = $doc[$lid];
            break;

        // Others here...

        default:
            $link = 'gallery.php';
    }

    return $link;
}
用法示例:

<a href='galleries.php?id=<? displayGalleryId($lid); ?> '>

您需要使用$\u服务器全局数组。。
您可以使用$\u服务器['SCRIPT\u FILENAME']或$\u服务器['REQUEST\u URI']

可能是

function getLink($id)
{
 $uri             = $_SERVER['REQUEST_URI'];
 $is_page_home    = (strstr($uri, 'home') === true)?true:false;
 $is_page_photos= (strstr($uri, 'photos') === true)?true:false;
 $is_page_document = (strstr($uri, 'document') === true)?true:false;
 if( $is_page_home )
 {
    $urlid = $id
 }
 if( $is_page_photos)
 {
   $urlid = $doc[$id]
 }
 if( $is_page_document )
 {
  $urlid = $photo[$id]
}
return $urlId
}

$urlId =  getLink($id)

<a href='galleries.php??id=<?=$urlId?>'>
函数getLink($id) { $uri=$\u服务器['REQUEST\u uri']; $is_page_home=(strstrstr($uri,'home')==true)?true:false; $is_page_photos=(strstrstr($uri,'photos')==true)?true:false; $is_page_document=(strstrstr($uri,'document')==true)?true:false; 如果($is\u page\u home) { $urlid=$id } 如果($is\u page\u photos) { $urlid=$doc[$id] } 如果($is\U页面\U文档) { $urlid=$photo[$id] } 返回$urlId } $urlId=getLink($id)

感谢新的开发者。这两种方法的区别是什么?我在选择它们之间应该考虑什么?“珍妮,你问了两个答案吗?