我已經從「PHP和mySQL新手到忍者」一書中做了一個測試數據庫......現在我正在測試通過使用模板輸出html來使結構更好。這是模板...用asterixes記錄部分。這是根據傳遞給它的頁面應該改變的動態內容。如何在模板中有效地加載頁面
<!DOCTYPE html>
<html lang="en">
<head>
<link href= "/project/includes/style.css" rel="stylesheet" type="text/css">
<meta charset="utf-8">
<title>Joke Database Project</title>
</head>
<body>
<div id="topheader">
<p>Joke Database Project</p>
</div>
<div id="navigation">
<?php include $_SERVER['DOCUMENT_ROOT'] .'/project/includes/navbar.html.php'; ?>
</div>
<div id="container">
**<?php include '/'.$content;?>**
</div>
</body>
</html>
,當我在我的PHP腳本使用下面的代碼,它工作正常:
$content="authors.html.php";
include $_SERVER['DOCUMENT_ROOT'] . '/project/includes/html_template.html.php';
但是我想使它不那麼笨重,所以我決定創建我helpers.inc以下功能。這包括在主PHP腳本php文件:
function showpage($content)
{
include $_SERVER['DOCUMENT_ROOT'] . '/project/includes/html_template.html.php';
}
所以,我只是想用SHOWPAGE(「author.html.php」)顯示在日的內容e模板。我遇到的問題是當我使用這個函數時,它不再識別主腳本中的變量。
如何以優雅的方式解決這個問題?
你有沒有使用類似刀片的模板引擎?你的應用程序太過於矯枉過正了嗎? – 2014-09-27 18:09:43