我正在使用Php编程,我需要通过网页使这些元素保持不变:
标题,侧边栏和页脚(所有php文件)
所有这些文件定义了各自的函数,比如create_header()等生成html,我有一个css来布局这些元素(使用div id =" header",id ="侧栏" ..)
至于实际内容的页面,他们所做的只是包含这些文件,拨打电话然后生成各自的内容,所有布局都通过div,所有内容都在div class =" content"
将这个用于每个页面或使用哪种方法是一种好习惯吗?
答案 0 :(得分:0)
这是我在用PHP编程时使用的系统,它对我很有用。这是确保一致性的好方法,前提是您记得将包含添加到所有页面。它还使更新网站的布局更容易。令人遗憾的是,PHP中没有模板或母版页,这将更加强大。但是,我强烈建议使用HTML的新语义标记,包括<header>
,<footer>
和<sidebar>
,而不是将id提供给适当的<div>
。
答案 1 :(得分:0)
这是我用于我的应用程序。看看这是否有帮助:
site_config.php:
<?php
define('DIR_BASE', dirname( dirname(__FILE__) ));
define('DIR_CLASSES', DIR_BASE . '/classes/');
// this is specific to the site
define('DIR_SITE', DIR_BASE . '/yoursite/');
define('SITE_NAME', 'yoursite');
// these would be specific to this site only
define('DIR_SITE_VIEWS', DIR_SITE . 'views/' );
define('DIR_SITE_COMPONENTS', DIR_SITE . 'components/');
define('BASE_URL', 'http://'.$_SERVER['SERVER_NAME']);
define('SITE_URL', BASE_URL . '/yoursite');
// static content for the site
define('DIR_STATIC', SITE_URL . '/static');
define('DIR_JS', DIR_STATIC . '/js');
define('DIR_CSS', DIR_STATIC . '/css');
define('DIR_SITE_IMG', SITE_URL . '/images');
?>
这就是我的模板:
<?php
// site_template.php
// template for adding a new page directly under main directory of this site
require_once('site_config.php');
$pgtitle = "Title of the Page";
include_once(DIR_SITE_VIEWS . 'site_header_begin.php');
// custom css/javascript goes here
include_once(DIR_SITE_VIEWS . 'site_header_end.php');
?>
<?php
// main content of the page goes here
?>
<?php
include_once(DIR_SITE_VIEWS . 'site_footer.php');
?>
site_header_begin.php:
<!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>
<title>
<?php if (isset($pgtitle) && ($pgtitle != '')){echo $pgtitle." :: ";}?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="AUTHOR" content="" />
<meta name="KEYWORDS" content="" />
<meta name="DESCRIPTION" content="" />
<!-- common css goes here -->
<script type="text/javascript" language="javascript" charset="utf-8" src="http://code.jquery.com/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.8.17/jquery-ui.min.js"></script>
site_header_end.php:
</head><!-- end the header here -->
<body ><!-- start the body here -->
site_footer.php:
<div id="footer"><a name="pageFooter"></a>
</div>
</body>
</html>
这将使页眉/页脚“不变”和动态,所有内容都将根据site_config.php文件中定义的常量进行定义。您只需添加适当的视图,静态,类和组件目录。看看这是否有帮助。
答案 2 :(得分:0)
include
函数是使网站模板保持不变的好方法
标题和左窗格。
in1.php (this file contains top part of the constant interface)
<?php
//session maintenance code:
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Admin interface</title>
<link rel="stylesheet" type="text/css" href="../css/pageBody.css" />
<link rel="stylesheet" type="text/css" href="../css/dropdown.css"/>
</head>
<body>
<!--top divisor-->
<div id="topp">
<center>
top pane content should be coded here
</center>
</div>
<!--end of the top divisor-->
< div id="bottom">
<!--start of the left pane-->
<div id="leftd" >
<P>
left pane content should be coded here:
</P>
</div>
然后脚(底部)部分
in2.php (this file contains the constant end part of the web site)
<!--start of the footer-->
<div id="foot" style="">
<center class="footfix">
©KS <a href="http://ugvle.ucsc.cmb.ac.lk">visit us</a>
</center>
</div>
<!--end of the footer-->
<div></div>
</body>
</html>
最后,我们可以定义网站的动态部分。我已经演示了一个登录窗口。
login.php
<?php
include 'in1.php'; //previously made top part
?>
<!--start of the dynamic main pane-->
<div id="rightd" >
<form name="login" action="user.php" method="post">
<table>
<tr><td>Email: </td><td colspan="2" ><input type="text" name="email" size="30" required/></td></tr>
<tr><td>password: </td><td colspan="2"><input type="text" name="pass" size="30" required/></td></tr>
<tr><td></td><td><input type="submit" value="OK" name="log"/><input type="reset" value="clear" /></td></tr>
</table>
</form>
<?php
//a php code here:
?>
</div>
<!--end of the dynamic main pane-->
<?php
include 'in2.php'; //previously made footer part
?>