1
我試圖在php中創建一個小引導。創建一個php引導文件 - 無法訪問文件
我迪爾斯是這樣的:
./application
./application/_styles
./application/_img
./application/views
./application/views/index
./application/views/error
./application/controllers/
./application/models/
./application/Bootstrap.php
./.htaccess
的.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ application/Bootstrap.php [NC,L]
bootstrap.php中:
<?php
#set up the project to developing state
error_reporting(E_ALL);
ini_set('display_errors','On');
#let's set up a root path constant
define('ROOT',getcwd().DIRECTORY_SEPARATOR);
#useful conf.
define('IMG', ROOT.'views/_img/');
define('CSS', ROOT.'views/_styles/');
$projectUrl = "http://www.neophp.com/";
$siteUrl = "http://www.neophp.com";
class neoPHP{
#== Method to get current URL request ==#
private function zinit(){
#get variables
$host = $_SERVER['HTTP_HOST'];
$self = $_SERVER['REQUEST_URI'];
$query = !empty($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : null;
$url = !empty($query) ? "http://$host$self?$query" : "http://$host$self";
#sort data
$request = str_replace($GLOBALS['projectUrl'], "", $url);
$request = explode("/",$request);
$request = array_filter($request);
#make readable
$load = array();
foreach($request as $rq){
$load[] = $rq;
}
#return information
return $load;
}
public function getClasses(){
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir(ROOT.'models/');
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
if ($file != "." && $file != ".." && strstr($file, '.php')) {
$results[] = $file;
}
}
// tidy up: close the handler
closedir($handler);
// done!
foreach($results as $class){
include_once (ROOT.'models/'.$class);
}
}
#== Method to load requred pages ==#
public function zinitLoad(){
$this->getClasses();
$items = $this->zinit();
#include all models
global $neo;
global $users;
if(sizeof($items) == 0) {
if (file_exists(ROOT.'controllers/index/index.php') && file_exists(ROOT.'views/index/index.phtml')){
include_once(ROOT.'controllers/index/index.php');
include_once(ROOT.'views/layout/layout.phtml');
include_once(ROOT.'views/index/index.phtml');
include_once(ROOT.'views/layout/footer.phtml');
} else {header('Location: '.$GLOBALS['projectUrl'].'error/');}
}elseif(sizeof($items) == 1) {
if (file_exists(ROOT.'controllers/'.$items['0'].'/index.php') && file_exists(ROOT.'views/'.$items['0'].'/index.phtml')){
include_once(ROOT.'controllers/'.$items['0'].'/index.php');
include_once(ROOT.'views/layout/layout.phtml');
include_once(ROOT.'views/'.$items['0'].'/index.phtml');
include_once(ROOT.'views/layout/footer.phtml');
} else {header('Location: '.$GLOBALS['projectUrl'].'error/');}
}
elseif (sizeof($items >= 2)){
if (file_exists(ROOT.'controllers/'.$items['0'].'/'.$items[1].'.php') && file_exists(ROOT.'views/'.$items['0'].'/'.$items[1].'.phtml')){
include_once(ROOT.'controllers/'.$items['0'].'/'.$items[1].'.php');
include_once(ROOT.'views/layout/layout.phtml');
include_once(ROOT.'views/'.$items['0'].'/'.$items[1].'.phtml');
include_once(ROOT.'views/layout/footer.phtml');
} else {header('Location: '.$GLOBALS['projectUrl'].'error/');}
}
}
#== Method to print arrays ==#
public function show($arr){
echo '<pre>';print_r($arr);echo '</pre>';
}
}
$neo = new neoPHP();
$neo->getClasses();
$neo->zinitLoad();
//print_r(getDirectoryList(ROOT));
//if (class_exists('Users')) echo 'exists';
?>
我的問題是用HTML代碼。當我嘗試調用* .css文件或* .png文件時,該腳本返回到錯誤頁面。我以爲
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
將解決這個問題,但它doesn't。
因此,我需要一些幫助/建議來訪問此設置的文件,或任何其他建議。