0

我正在使用 Php 编程,我需要通过网页保持这些元素不变:
页眉、侧边栏和页脚(所有 php 文件)

所有这些文件都定义了相应的函数,如 create_header() 等生成 html,我有一个布局这些元素的 css(使用 div id="header",id="sidebar"..)

至于实际内容的页面,他们所做的只是包含这些文件,进行调用然后生成各自的内容,所有布局都通过 div 进行,它们的所有内容都在 div class="content" 中

对每个页面使用它是一种好习惯还是我应该使用哪种方法?

4

3 回答 3

0

这是我在使用 PHP 编程时使用的系统,它对我来说效果很好。这是确保一致性的好方法,前提是您记得将包含添加到所有页面。它还使更新网站的布局更容易。遗憾的是 PHP 中没有模板或母版页,这会更健壮。但是,我强烈推荐 HTML 的新语义标签,包括<header>,<footer><sidebar>不是将 id 赋予适当<div>的 's。

于 2013-07-23T15:51:03.150 回答
0

这就是我用于我的应用程序的内容。看看这是否有帮助:

站点配置.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 文件中定义的常量进行定义。您只需要添加适当的视图、静态、类和组件目录。看看这是否有帮助。

于 2013-07-23T15:52:37.923 回答
0

includePHP中的函数是使网站模板保持标题和左窗格不变的好方法。

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">
            &copy;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
?>
于 2017-05-30T16:09:30.180 回答