dr5648 2017-09-22 13:05
浏览 24

从单个标头生成带有php的页面

Im trying to use make php generate pages by only including a header, is that even possible? Or must I use includes within the page for page components?

<?php
include($_SERVER['DOCUMENT_ROOT'].'/api/header.php');
$GLOBALS['pagetype'] = "main";
$GLOBALS['$pagetitle'] = "Test";

/* content goes here */
?>

Ideally I want all pages to follow this template.

One of my layouts is something like this:

Page headerbar
----
Content
----
Navigation Index

How can I make it place the page content in the correct place?

EDIT: I suck at explaining stuff, sorry about that. What I want is actually, to make a header.php to do all the "include" work for the pages. So I don't need to place includes within specific positions of a page.

  • 写回答

3条回答 默认 最新

  • duansaoguan7955 2017-09-22 13:38
    关注

    Like @ADyson says, make a header.php page like this:

    <?php
    
     //use require_once('exampleclass.php'); if you want to use OOP- classes and
     //put all other php code here
    
    ?>
    
    <html>
       <head>
           <link rel="stylesheet" href="styles.css"/>
       </head>
       <body>
    
       //put your html code here and use css to make it prettier
    
       </body
    </html>
    

    Then in your other pages that need to use this page, put this in your php files:

    <?php
    
    include('header.php');
    
    ?>
    

    It is that simple really, just keep including the header.php page and put different html code for the content in those pages.

    Hope this answers your question! Ramon

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么