没用框架,只用了smarty,然后问题就出来了,我自建那些controller ,model类找不到,于是只能在hotdocs里写do.php这样程序,通过它进行到这些文件中。所以,请大侠们有什么更好的办法。听说什么路由,分发器之类 的。
这些具体的作用是啥,能不能用来,上述那样的寻找文件夹进行处理,还有那个rewrite等等,不用框架真得很麻烦。有没有这样的类,共享一下,大侠们。请大师传道受业解惑者也。
这些具体的作用是啥,能不能用来,上述那样的寻找文件夹进行处理,还有那个rewrite等等,不用框架真得很麻烦。有没有这样的类,共享一下,大侠们。请大师传道受业解惑者也。
http://www.domain.com/abc/def
那么在请求中就在入口文件中加载controller中的abc.php文件中的def方法等等...
+adodb
+cache
+configs
+controller
+htdocs
-index.php
-do.php
+initcase
+model
+port
+smarty
+templates
+templates_c
基本结构就是这样,有点听懂妖言的意思,但具体的思路很没有,如果有源程序之类的就更好了,呵呵
// 以下是我随意举个例子,重在思路,不必计较function __autoload($con){
if(strpos($con, 'Controller') !== false && is_file(ROOT_PATH.'Controller/' . $con . '.php')){
require_once(ROOT_PATH . 'Controller/' . $con . '.php');
}else if(strpos($con, 'Model_') !== false && is_file(ROOT_PATH . 'Model/' . str_replace('Model_', '', $con) . '.php')){
require_once(ROOT_PATH . 'Model/' . str_replace('Model_', '', $con) . '.php');
}else if(strpos($con, 'Common_') !== false && is_file(ROOT_PATH . 'Common/' . str_replace('Common_', '', $con) . '.php')){
require_once(ROOT_PATH . 'Common/' . str_replace('Common_', '', $con) . '.php');
}else{
//默认调用该方法,如果不执行该else,那么程序会向下执行
IndexController::indexAction();
exit;
}
}//function dispatch(){
// global $rewrite;
session_start();
// if($rewrite){
// $uri = $_SERVER['REQUEST_URI'];
// if($_SERVER['REQUEST_METHOD']){
// $uri = strtr($uri, array('?' => '/', '=' => '/', '&' => '/'));
// }
// global $request;
// $request = explode('/', $uri);
// array_shift($request);
// $con = isset($request[0]) && trim($request[0])? $request[0]: 'index';
// $act = isset($request[1]) && trim($request[0])? $request[1]: 'index';
// function getParam($var = '') {
// global $request;
// if($var){
// $key = array_key_exists($var, $request);
// if($key !== false){
// return $request[$var];
// }else{
// $key = array_search($var, $request);
// if(($key !== false) && ($key % 2 == 0) && (isset($request[$key + 1]))){
// return $request[$key + 1];
// }
// return ;
// }
// }else{
// $count = count($request);
// $arr = array();
// if(isset($request[0]) && $request[0]){
// $arr['controller'] = $request[0];
// }
// unset($request[0]);
// if(isset($request[1]) && $request[1]){
// $arr['action'] = $request[1];
// }
// unset($request[1]);
// for($i = 2; $i < $count; $i = $i + 2){
// $arr[$request[$i]] = $request[$i + 1];
// }
// if(isset($GLOBALS['HTTP_POST_VARS']) && $GLOBALS['HTTP_POST_VARS']){
// foreach($GLOBALS['HTTP_POST_VARS'] as $key => $value){
// $arr[$key] = $value;
// }
// }
// return $arr;
// }
// }
// }else{
$con = isset($_REQUEST['con'])? $_REQUEST['con']: 'index';
$act = isset($_REQUEST['act'])? $_REQUEST['act']: 'index';
// } $con = $con . 'Controller';
if(!class_exists($con)){
throw new Exception('Controller ' . $con . ' does not exist.');
}
$act = $act . 'Action';
if(!method_exists($con, $act)){
throw new Exception('Not exist Action ' . $act . ' in Controller ' . $con . '.');
}
$con = new $con();
$con->$act();
//}
RewriteRule !(.js|.jpg|.gif|.bmp|.css|.rar|.txt|.swf|.flv|.html) Index\.php