2011-05-28 68 views
0

我有16個文件用PHP中就包括包括一個PHP模板是這樣的:文檔名稱包括

<?php include("templates/template.php"); ?> 

內部的模板有哪些發現文件名PHP的一點點,打印它。問題在於,要包含PHP文檔,它的PHP將被處理(當然是因爲它的PHP),這意味着文檔名稱查找程序正在查找模板的名稱而不是主文檔。我試圖做的是有16個PHP文件作爲前端,並由用戶訪問,這些文件包括模板文件,該文件找到被訪問文件的名稱,並從另一個文件中將HTML代碼拉入模板。這意味着文件的內容在網站的結構之外,並且允許基本編輯的簡單程度(I.E.客戶可以編輯他們的網站)。正如我上面說我的方法有什麼,我試圖找出一個簡單的問題是,如果反正知道如何做這一信息。模板文件被粘貼下面

<!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:[email protected]">Information: [email protected]</a><br /> 
      <a href="mailto:[email protected]">Bookings: [email protected]</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> 

許多在此先感謝。

+0

您的模板文件404's;張貼相關的代碼。 – Ross 2011-05-28 10:48:07

+0

@Ross對不起,該文件夾是模板現在不修復模板。考慮到它的PHP,我會發布代碼。我在想什麼? – Jason 2011-05-28 10:49:32

回答

1

模板應該是一段代碼,它需要參數並基於該代碼生成輸出。

這個問題的解決方案可能是,在那個被訪問的文件中,你聲明一個具有適當名稱的變量並將它傳遞給模板。在那裏您將按照要求區分每個頁面。

解決方案

魔術不斷__FILE__持有包含的文件名,如果在使用包括。所以解決方法是將php代碼移動到您正在運行include的文件中。

+0

問題仍然是開放的,我目前的拼湊解決方案太把模板分成兩個文件,並將文檔名稱放入包含模板的文檔中。 – Jason 2011-05-28 11:06:10

+0

我明白了,我發現一個規範說,__FILE__總是保存文件/ included_file的名稱。因此,您的基本名稱部分將始終將__FILE__視爲模板。看到這裏[php魔術常量](http://php.net/manual/en/language.constants.predefined.php) – koressak 2011-05-28 11:16:34

+0

我所做的只是移動了php腳本,它從包含的文件中找出文檔名稱它找到正確的文檔名稱。 – Jason 2011-05-28 11:22:42