Frontcontroller help
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
php
<?php
$pagesDir = "pages";
// Get the request
$page = $_SERVER['REQUEST_URI'];
// Strip the first slash
$page = substr($page, 1);
// Prevent access to higher level folders
$page = str_replace('..', '', $page);
// Do some mapping to actual files in a subfolder
$page = "$pagesDir/$page";
// Serve an error page if not found
if (!file_exists($page)) {
$page = "$pagesDir/error.html";
}
// Prevent anything from being output until it is ready
ob_start();
include($page);
$contents = ob_get_clean();
// Use a template with the variable $contents where you want the page's content to go
ob_start();
include($template);
$output = ob_get_clean();
echo $output;
?>
Warning: include() [function.include]: Failed opening '' for inclusion (include_path='.;C:php5pear') in C:wampwwwindex.php on line 29
$template
被评估为一个空字符串,而且我也没有看到它在PHP源代码中的任何地方声明。
上一篇: 错误代码,并不会在PHP中工作
下一篇: 前端控制器的帮助