没用框架,只用了smarty,然后问题就出来了,我自建那些controller ,model类找不到,于是只能在hotdocs里写do.php这样程序,通过它进行到这些文件中。所以,请大侠们有什么更好的办法。听说什么路由,分发器之类 的。
这些具体的作用是啥,能不能用来,上述那样的寻找文件夹进行处理,还有那个rewrite等等,不用框架真得很麻烦。有没有这样的类,共享一下,大侠们。请大师传道受业解惑者也。

解决方案 »

  1.   

    但入口模式进行分发请求是框架最常用的技术也是框架的一大亮点,这要结合rewrite来控制单入口
      

  2.   

    其实楼主你只需要加个规则让请求访问到当前域中重定向到入口文件,然后入口文件根据文件名(要规则这点)分发请求例如:
    http://www.domain.com/abc/def
    那么在请求中就在入口文件中加载controller中的abc.php文件中的def方法等等...
      

  3.   

    +project
      +adodb
      +cache
      +configs
      +controller
      +htdocs 
         -index.php
         -do.php
      +initcase
      +model
      +port
      +smarty
      +templates
      +templates_c
    基本结构就是这样,有点听懂妖言的意思,但具体的思路很没有,如果有源程序之类的就更好了,呵呵
      

  4.   

    // index.php 每当请求时候都经过index.php 所以找不到方法__autoload就会自动运行,你再__autoload中添加规则(所以文件命名要规范哦)
    // 以下是我随意举个例子,重在思路,不必计较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();
    //}
      

  5.   

    你只需要在apache或者.ht文件中定义规则让请求重定向到上面文件中(index.php)就行了,例如规则:RewriteEngine on
    RewriteRule !(.js|.jpg|.gif|.bmp|.css|.rar|.txt|.swf|.flv|.html) Index\.php
      

  6.   

    大侠,请教问题啊,如4楼结构,我的index.php是在htdoc下,每次请求时想首先进去index.php不行啊,比如,输入:http://test/test2.php 或是http://test/use/1目录直接去找该网页。怎么做?
      

  7.   

    我现在是用这样的结构,http://test/index.php/test2.php可以套用,但是把smarty必须写在某个controller类的外面,不能写在里面。这样就麻烦了。