0

リクエストとルータークラスがあります-動作しますが、アクションを実行しようとすると結果がありません

例えば。ローカルホスト/テスター/テスト

索引

$router = OOP_Controller_Router::getInstance();
$request = new OOP_Controller_Request();
$router->dispatch($request);

リクエスト

class OOP_Controller_Request {

    private $_requestParams = array ();
    public $_defaultController;

    public function __construct(){

        $filter_ALL = new OOP_InputFilter();

        $address1   = parse_url( $_SERVER['REQUEST_URI'] );
        $path   = explode('/', trim($address1['path'],'/') );

        $parameters1['controller'] = $filter_ALL->process( str_replace('-','',strtolower($path[0])) );
        $parameters1['action'] = $filter_ALL->process( str_replace('-','',strtolower($path[1])) );

        array_shift($path);
        array_shift($path);
        $path = array_chunk($path, 2);
        for( $i=0;$i<count($path);$i++ ){
            if( !isset($path[$i][1]) ) { $path[$i][1] = 1; }
            $parameters1[ $path[$i][0] ] = $path[$i][1];
        }

        $this->_requestParams = array_merge($_REQUEST,$parameters1);

        $_REQUEST   = array();
        $_POST      = array();
        $_GET       = array();
    }

    public function getParam($paramName){
        if(isset($this->_requestParams[$paramName])){
            return $this->_requestParams[$paramName];
        } else {
            return false;
        }
    }

    public function setParam($paramName,$paramValue){
        $this->_requestParams[$paramName] = $paramValue;
    }
}

router $controllerClass = new $controllerClassName($request->getParam('action')); - このクラスはロードしますが、アクションはロードしません

class OOP_Controller_Router implements OOP_Controller_Interface{

    private $controllerFileNamePrefix;
    private $controllerFileNameSufix;
    private static $instance;

    private function __construct(){
        define('APP_PATH',$_SERVER['DOCUMENT_ROOT'].'/');

        $this->_controllerFileNamePrefix = APP_PATH.'controllers/';
        $this->_controllerFileNameSufix = '.php';
    }

    private function __clone(){
        trigger_error('Clone done', E_USER_ERROR);
    }

    public function __wakeup(){
        trigger_error('Deserialaze cannot done', E_USER_ERROR);
    }

    public static function getInstance(){
        if (!self::$instance instanceof self){
            self::$instance = new self;
        }
        return self::$instance;
    }

    public function dispatch(OOP_Controller_Request $request){

        $controllerClassName = 'controllers_'.$request->getParam('controller');

        //if controller != ''
        if ($request->getParam('controller')!=''){
        //if file exists load this
            if( file_exists($this->_controllerFileNamePrefix . $request->getParam('controller') . $this->_controllerFileNameSufix) ){


*$controllerClass = new $controllerClassName($request->getParam('action'));*
        //if file !exists load default controller
            } else {
                $controllerClass = $request->_defaultController;
            }
    //if controller = '' load default controller
        } else {
            $this->dispatch_default_controller($request,2);
        }
    }

    public function dispatch_default_controller(OOP_Controller_Request $request, $action_dispatch){
        global $myconf;
        $default_controller = 'controllers_'.$myconf['default_controller'];
        $request->setParam('controller',$myconf['default_controller']);

        $controllerClass    = new $default_controller($request,$action_dispatch);
    }

}

なにが問題ですか ?

4

0 に答える 0