PHP模板站点瓦特/ file_get_content链接
好吧,所以我有一个模板脚本我的朋友为我建成。我将包含所有文件名。PHP模板站点瓦特/ file_get_content链接
OK那么,什么是不工作的file_get_contents是不掠内容
(1我不知道在哪里的内容应该放置。
(2我希望它放置在一个目录中,以便如果我改变模板的内容保持区域是一样的
(3我想获取file_get_contents加载链接?=约?=服务等进入body.tpl在内容div我指定with#CONTENTS#
(4 T他迪尔树如下
htdocs>
classes> file.class.php
contents> where i want #CONTENTS# (file_get_contents) to grab data from
images> content (changing images)
templates> where the templates are hosted
clean>main template (Files are header.tpl, body.tpl, footer.tpl, styles.css, menu_style.css, and the images folder for images relating to the template itself.)
other templates>(to come)
请任何帮助表示赞赏。现在的问题是脚本是否将所有内容都放在正确的区域加载它,而不是显示它?
/* * file.class.php/
<?php
$file = new file();
class file{
var $path = "templates/clean";
var $ext = "tpl";
function loadfile($filename){
return file_get_contents($this->path . "/" . $filename . "." . $this->ext);
}
function setcontent($content,$newcontent,$vartoreplace='#CONTENT#'){
$val = str_replace($vartoreplace,$newcontent,$content);
return $val;
}
function p($content) {
$v = $content;
$v = str_replace('#CONTENT#','',$v);
print $v;
}
}
if(!isset($_GET['page'])){
// if not, lets load our index page(you can change home.php to whatever you want:
ob_start();
include("contents/".'main.php');
$content = ob_get_contents();
ob_end_clean();
// else $_GET['page'] was set so lets do stuff:
} else {
// lets first check if the file exists:
if(file_exists($_GET['page'].'.php')){
// and lets include that then:
ob_start();
include("contents/". $_GET['page'] . '.php');
$content = ob_get_contents();
ob_end_clean();
// sorry mate, could not find it:
} else {
echo 'Sorry, could not find <strong>' . $_GET['page'] .'.php</strong>';
}
}
?>
,如果一些人可以修剪下来所以它只是为模板所需的代码和文件获取内容。
/*的index.php */
<?php
include('classes/file.class.php');
// load the templates
$header = $file->loadfile('header');
$body = $file->loadfile('body');
$footer = $file->loadfile('footer');
// fill body.tpl #CONTENT# slot with $content
$body = $file->setcontent($body, $content);
// cleanup and output the full page
$file->p($header . $body . $footer);
?>
/* header.tpl */
<!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" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<meta name="robots" content="index,follow"/>
<meta name="distribution" content="global"/>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<link href="templates/clean/style.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="templates/clean/menu_style.css" type="text/css" />
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
</head>
<body>
<div id="header">
<div id="logo"><a href="index.php" style="height:30px;width:150px;"><img src="images/logo.png" border="0" alt=""/></a></div>
<div id="menuo">
<div class="menu">
<ul id="menu">
<li><a href="?page=home">Home</a></li>
<li><a href="?page=about">About Us</a></li>
<li><a href="?page=services">Services</a>
<ul>
<li><a href="?page=instore">InStore Repairs</a></li>
<li><a href="?page=inhome">InHome Repairs</a></li>
<li><a href="?page=website">Website Design</a></li>
<li><a href="?page=soon">Comming Soon.</a></li>
</ul>
</li>
<li><a href="?page=products">Products</a>
<ul>
<li><a href="?page=pchard">Computer Hardware</a></li>
<li><a href="?page=monitor">Monitor's</a></li>
<li><a href="?page=laptop">Laptop + Netbooks</a></li>
<li><a href="?page=soon">Comming Soon.</a></li>
</ul>
</li>
<li><a href="?page=contact">Contact</a></li>
</ul>
</div>
</div>
</div>
<div id="headerf">
</div>
/* body.tpl */
<div id="bodys">
<div id="bodt"></div>
<div id="bodm">
<div id="contents">
#CONTENT#
</div>
<div id="bodb"></div>
</div>
</div>
/* foo ter.tpl */
<div id="footer">
<div style="position:absolute; top:4px; left:4px;"><img src="images/ff.png" alt="ok"></div> <div style="position:absolute; top:4px; right:5px; color:#FFFFFF;">©2010 <a href="mailto:">Company Name</a></div>
</div>
</body>
</html>
据我所知,你的内容是about.php(例如)。
这个文件是在 “内容” 目录:内容/ about.php
命令
include('about.php')
将加载并执行脚本about.php在线。因此,它将在包括呼叫完成的地方准确打印其内容。你看到的一定是这样的:
(content of about.php) | header | body | footer
如果你想$内容有正确的值,改线
include($_GET['page'].'.php');
与
ob_start();
include("contents/". $_GET['page'] . '.php');
$content = ob_get_contents();
ob_end_clean();
这将使用对象缓冲技术为了使PHP明白它不应该呈现文件的内容,而是将其放在$ content变量中。
我希望这有助于!
我试着做你说的话,它不会改变一件事。我试了两个更新它在op – Zeenjayli 2010-03-31 16:50:16
我修改了剪切,以考虑到“about.php”在“contents/about.php”中的事实。告诉我它是否工作。 请不要保留“爆炸”版本ob_start/ob_end_clean。你需要有 ob_start(); INCLUDE(.....) $ content = ob_get_contents(); ob_end_clean();每个包括 。我会澄清,如果这不明确。 如果这不起作用,您可以详细说明 1 /您在浏览器中调用的URL是什么? 2 /你在看什么? 杰罗姆 – 2010-03-31 18:04:25
天才!非常感谢,很好的工作,内容是现在应该在哪里(发现,因为它正在寻找内容/ main.php,它不在那里,所以它显示没有找到行话,直到我把它放在文件夹坏的新问题出现我已经更新了我的代码,以显示我已经完成了 – Zeenjayli 2010-03-31 20:29:03
您的朋友为您构建的模板脚本中充满了可帮助您模板化网站的辅助函数。
目前,我觉得你有2个问题:
- 的模板的位置
- 使用模板机制
1的模板
位置目前,你的朋友的脚本状态
var $path = "templates/clean";
这意味着你应该创建一个模板文件夹,并在你已经把的index.php目录中模板/清洁文件夹,并把你的模板(header.tpl,body.tpl,footer.tpl )里面。
2。使用模板机制
尝试使用
<?php
include('classes/file.class.php');
// load the templates
$header = $file->loadfile('header');
$body = $file->loadfile('body');
$footer = $file->loadfile('footer');
// fill body.tpl #CONTENT# slot with "Hello World!"
$body = $file->setcontent($body, "Hello World!");
// cleanup and output the full page
$file->p($header . $body . $footer);
?>
的setcontent找到#内容#在预加载body.tpl的发生,并与特定的内容替换它(在这种情况下,“Hello World”的)
我希望这会让你走上良好的轨道!告诉我它是否有效。 杰罗姆
好所以是什么被添加“$ body = $ file-> setcontent( $ BOD y,$ content);“像你说的,但改变了“Hello World!”到“$ content”,所以它读取该标签,它的工作原理是使用 “if(isset($ _ GET ['page'])){ $ content = $ _GET ['page']。'。php' ; } else { $ content ='main.php'; }“ 因此,当我点击左右并且脚本读取 Zeenjayli 2010-03-30 23:36:33
我认为你的问题可能是上线
if(file_exists($_GET['page'].'.php')){
它应该阅读
if(file_exists('contents/'.$_GET['page'].'.php')){
希望这有助于
,所以我知道它不是一个CSS/HTML问题现在好了,至少不是HTML我跑了validator.w3.org传递与飞行的颜色网站问题的情况下,任何人都需要看看它是designed.sytes.net – Zeenjayli 2010-03-31 17:31:05