前控制器的帮助

时间:2009-07-06 22:18:41

标签: php

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;

?>

警告:include()[function.include]:无法在C:\ wamp \ www \ index.php中打开''包含(include_path ='。; C:\ php5 \ pear') 29

1 个答案:

答案 0 :(得分:1)

$template被评估为一个空字符串,我不认为它在你的PHP源代码中的任何地方声明。