本文介绍了make header,sidebar&页脚常量跨网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Php编程,我需要这些元素通过网页不变:

header,sidebar& footer(所有php文件)

I am programming with Php and i need these elements constant through the web page:
header, sidebar & footer (all php files)

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

all these files define the respective functions like create_header() and so on that generate the html and i have a css that layout these elements (using div id="header",id="sidebar"..)

对于实际内容的页面,它们都包括这些文件,生成它们各自的内容,所有的布局都通过div,所有的内容都在div class =content里面

as for the pages of actual content all they do is include this files, make the calls and then generate their respective content, all layout through divs, all their content is inside the div class="content"

是一个很好的做法,我应该使用?

is it good practice to use this for each page or which method should i use?

推荐答案

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

This is what I use for my applications. See if this helps:

site_config.php:

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:

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:

site_header_end.php:

</head><!-- end the header here -->
<body ><!-- start the body here -->

site_footer.php:

site_footer.php:

        <div id="footer"><a name="pageFooter"></a>
        </div>
    </body>
</html>

这将使页眉/页脚常量和动态,在site_config.php文件中。您只需要添加适当的视图,静态,类和组件目录。看看这是否有帮助。

This will make header/footer "constant" and dynamic and everything will be defined in terms of constants defined in the site_config.php file. You just need to add appropriate views, static, classes and components directories. See if this helps.

这篇关于make header,sidebar&amp;页脚常量跨网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 08:22