Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 请求和路由器don';t荷载作用_Php_Oop_Class_Request_Router - Fatal编程技术网

Php 请求和路由器don';t荷载作用

Php 请求和路由器don';t荷载作用,php,oop,class,request,router,Php,Oop,Class,Request,Router,我有request和router类-它可以工作,但当我尝试运行操作时,它没有任何结果 比如说。 localhost/tester/test 索引 请求 class OOP_Controller_Request { private $_requestParams = array (); public $_defaultController; public function __construct(){ $filter_ALL = new OOP_Inp

我有request和router类-它可以工作,但当我尝试运行操作时,它没有任何结果

比如说。 localhost/tester/test

索引

请求

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;
    }
}

有什么问题吗?

首先,您使用的是单例。我必须做什么才能让它工作?您的控制器构造函数希望参数是什么?在您的代码中,我看不到您在创建的控制器上显式调用操作。为什么您认为应该对此对象调用操作?
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;
    }
}
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);
    }

}