我正在遵循这个Link来理解PHP Web应用程序的基本框架,但是我无法理解如何通过导航栏来回切换到不同的布局(文章,投资组合)?
答案 0 :(得分:0)
所有不同的布局都必须类似于index.php。
图像中包含articles.php和Portfolio.php。内容如下:
Articles.php:
<?php
// load up your config file
require_once("/path/to/resources/config.php");
require_once(TEMPLATES_PATH . "/header.php");
?>
<div id="container">
<div id="content">
<!-- Your article content here!!! -->
</div>
<?php
require_once(TEMPLATES_PATH . "/rightPanel.php");
?>
</div>
<?php
require_once(TEMPLATES_PATH . "/footer.php");
?>
和Portfolio.php:
<?php
// load up your config file
require_once("/path/to/resources/config.php");
require_once(TEMPLATES_PATH . "/header.php");
?>
<div id="container">
<div id="content">
<!-- Your portfolio content here!!! -->
</div>
<?php
require_once(TEMPLATES_PATH . "/rightPanel.php");
?>
</div>
<?php
require_once(TEMPLATES_PATH . "/footer.php");
?>
但是每次添加新页面时,都必须更新header.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Simple Site</title>
</head>
<body>
<div id="header">
<h1>Simple Site</h1>
<ul class="nav global">
<li><a href="path_to_index.php">Home</a></li>
<li><a href="path_to_article.php">Articles</a></li>
<li><a href="path_to_portfolio.php">Portfolio</a></li>
<li><a href="path_to_any_other_page.php">Any other page</a></li>
</ul>
</div>
答案 1 :(得分:0)
这是我实际上想要实现的目标
<nav>
<ul>
<li><a href="index.php?page=home">Home</a></li>
<li><a href="index.php?page=projects">Projects</a></li>
<li><a href="index.php?page=calculator">Calculator</a></li>
<li><a href="index.php?page=blog">Blog</a></li>
<li><a href="index.php?page=About">About</a></li>
</ul>
</nav>
我将页面变量发送到索引,然后通过这种方式相应地呈现布局。
if (isset($_GET["page"])){
$page=$_GET["page"];
}
else {
$page = "home";
}
renderLayoutWithContentFile($page .".php", $variables);