drot98385 2013-07-23 15:46
浏览 59
已采纳

使标题,侧边栏和页脚在网站上保持不变

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

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"..)

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?

  • 写回答

3条回答 默认 最新

  • dongzheng3113 2013-07-23 15:52
    关注

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

    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');
    ?>
    

    This is what my template looks like:

    <?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>
    

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看