首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >PHP中的文档名称包括

PHP中的文档名称包括
EN

Stack Overflow用户
提问于 2011-05-28 18:40:49
回答 1查看 176关注 0票数 0

我有16个文档,其中包含一个php,包括一个php模板,如下所示:

代码语言:javascript
复制
<?php include("templates/template.php"); ?>

在该模板内部有一小部分PHP,它可以找到文档名称并打印出来。问题是,对于要包含的php文档,其PHP被处理(自然是因为它是PHP),这意味着文档名称查找器查找的是模板的名称,而不是主文档的名称。我试图做的是有16个PHP文件,作为前端,并由用户访问,这些文件包括模板文件,找到被访问的文件的名称,并将html代码从另一个文件到模板的主体。这意味着文件的内容在网站结构的外部,并允许一定程度的简单性用于基本编辑(即客户端可以编辑其网站)。如上所述,我的方法有一个简单的问题,我试图弄清楚的是,是否知道如何做this.The模板文件粘贴在下面

代码语言:javascript
复制
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.5.2.min.js" type="text/javascript">
</script>
<link href="css/styles.css" rel="stylesheet" type="text/css" /> 
<script type="text/JavaScript"> 
<!--
var screenwidth = screen.width;
if (screenwidth < 1180){
document.write('<link rel="stylesheet" href="css/ldrop.css" type="text/css" media="screen" />');
}
else
{
document.write('<link rel="stylesheet" href="css/drop.css" type="text/css" media="screen" />');
}
// -->
</script> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> 
<title>Alignment Courses</title> 
<link rel="shortcut icon" href="favicon.png" />
</head>
<body onload="makerequest('templates/quote.php','quote'); return false;makerequest('editing/<?php echo basename(__FILE__, '.' . pathinfo(__FILE__, PATHINFO_EXTENSION)); ?>.php','main')">
<div id="menu"><a href="index.html"><img src="webpics/logo.png" width="225" height="150" onmouseover="this.src='webpics/logoinv.png'" onmouseout="this.src='webpics/logo.png'" style="float:left" alt="Exit To Banner"/></a>
<div id="logo"><a href="index.html"><img src="webpics/Yoga Health.png" alt="Yoga Health Townsville" width="458" height="43" vspace="20"
onmouseover="this.src='webpics/Yoga Health Inv.png'"
onmouseout="this.src='webpics/Yoga Health.png'"/></a><a href="gallery.php" class="visit">visit the photo gallery</a></div> 
<div id="nav" class="mainmenu"> 
<ul>
<li class="menu1"><a href="home.php">Home</a></li>
<li class="menu2"><a href="#">Classes</a>
<ul>
<li><a href="daily.php">Daily</a></li>
<li><a href="beginner.php">Beginner</a></li>
<li><a href="alignment.php">Alignment</a></li>
<li><a href="prepare.php">Preparation</a></li>
</ul>
</li>
<li class="menu3"><a href="#">Family Yoga</a>
<ul>
<li><a href="family.php">Family Yoga</a></li>
<li><a href="kids.php">Childrens Yoga</a></li>
<li><a href="prenatal.php">Prenatal Yoga</a></li>
</ul>
</li>
<li class="menu4"><a href="#">Prices</a>
<ul>
<li><a href="prices.php">Classes</a></li>
<li><a href="purchase.php">Equipment</a></li>
</ul>
</li>
<li class="menu5"><a href="events.php">Events/Workshops</a>
<ul>
<li><a href="dance.php">Dance</a></li>
</ul>
</li>
<li class="menu6"><a href="teachers.php">Our Teachers</a></li>
<li class="menu7"><a href="contact.php">Location</a></li>
</ul>
</div></div>
<div id="content"><div id="sidebar"><div id="sidebar">
        <p><strong class="MyriadPromain"><em>Contacts</em></strong><br />
          <span class="MyriadProcontact">Shop 3, 262 Woolcock Street, Currajong, 4812 <br />
          <a href="mailto:info@yogahealth.net.au">Information: info@yogahealth.net.au</a><br />
          <a href="mailto:bookings@yogahealth.net.au">Bookings: bookings@yogahealth.net.au</a><br />
          Phone: 07 47 751 154<br />
          Mobile: 0410 085 054<br /><br /></span>
          <span class="ArialGroup">For Enquiries Regarding Group Bookings<br /><a href="documents/Group Bookings.pdf">Click Here</a></span>
        </p>
        <p><a href="http://www.facebook.com/pages/Yoga-Health-Townsville/140216156034239"><img src="http://www.yogahealth.net.au/webpics/facebook.gif" width="120" height="45" /></a></p>
        <iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FYoga-Health-Townsville%2F140216156034239%23&amp;layout=box_count&amp;show_faces=false&amp;width=700&amp;action=like&amp;font=verdana&amp;colorscheme=light&amp;height=50" scrolling="No" frameborder="0" style="border:none; overflow:hidden; width:65px; height:65px;" allowtransparency="true"></iframe>
        <p>
          <a href="links.php" class="ArialGroup">Links to other Websites in our Community</a></p>
        <div class="quoteback">
        <a href="#" id="refresh"><img src="http://www.yogahealth.net.au/webpics/Refresh.gif" height="20px" width="20px" align="right" /></a>
         <div id="quote"><br \></div>
         </div>
         <br \>
<script src="http://widgets.twimg.com/j/2/widget.js"></script>
<script>
new TWTR.Widget({
  version: 2,
  type: 'profile',
  rpp: 4,
  interval: 6000,
  width: 250,
  height: 300,
  theme: {
    shell: {
      background: '#333333',
      color: '#ffffff'
    },
    tweets: {
      background: '#000000',
      color: '#ffffff',
      links: '#4aed05'
    }
  },
  features: {
    scrollbar: false,
    loop: false,
    live: false,
    hashtags: true,
    timestamp: true,
    avatars: false,
    behavior: 'all'
  }
}).render().setUser('YogaHealth1').start();
</script> 
         <?php include("templates/quotein.php"); ?>
      </div>
</div><div id="main"><?php include("editing/alignment.php"); ?></div></div>

<div id="footer"></div>
</body>
</html>

在此之前,非常感谢您。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-05-28 18:51:39

模板应该是一段代码,它接受参数并在此基础上生成输出。

这个问题的解决方案可能是,在访问的文件中,使用适当的名称声明一个变量,并将其传递给模板。在那里,您将根据请求区分每个页面。

解决方案

魔术常量__FILE__保存所包含文件的名称,如果在include中使用的话。因此,解决方案是将php代码移到运行include的文件中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6161131

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档