Fatal error: Class 'ViewController' not found

0

My project structure

InmyImports.phpfileIhavefollowingcode:

//UTILrequire_once'util/Constants.php';require_once'util/Page.php';//Controlrequire_once'control/ViewController.php';//Viewrequire_once'view/View.php';

Inmystart.phpfileIhavefollowingcode:

require_once'Imports.php';ini_set('display_errors',1);error_reporting(E_ALL);ViewController::showView();

InmyView.phpclassIhavefollowingcode:

classView{private$control;private$parametros;private$user;private$modulo=null;functionView(){}publicfunctiongetControl(){return$this->control;}publicfunctionsetControl($control){$this->control=$control;}publicfunctiongetParametros(){return$this->parametros;}publicfunctionsetParametros($parametros){$this->parametros=$parametros;}publicfunctiongetUser(){return$this->user;}publicfunctionsetUser($user){$this->user=$user;}publicfunctionhasPermission(){if($this->user!=null){if($this->modulo!=null){if(strcmp($this->modulo,$this->user->getTipo())!=0){returnfalse;}}returntrue;}returnfalse;}publicfunctionsetModulo($modulo){$this->modulo=$modulo;}publicfunctiongetModulo(){return$this->modulo;}

}

InmyViewController.phpclassIhavefollowingcode:

classViewController{privatestatic$instance=null;privatestatic$root=null;privatestatic$currentUrl=null;privatestatic$view;privatefunction__construct(){}publicstaticfunctiongetInstance(){//ContruirUrlAtual$server=$_SERVER['SERVER_NAME'];$endereco=$_SERVER['REQUEST_URI'];self::$currentUrl="http://" . $server . $endereco;

    //Retornando a Instancia da página
    if (!isset(self::$instance) && is_null(self::$instance)) {
        $c = __CLASS__;
        self::$instance = new $c;
    }
    return self::$instance;

}

public static function redirect($pagina){
    exit ('<script>top.location="'.$pagina.'"</script>');
}

public static function getCurrentUrl(){
    self::$currentUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    return self::$currentUrl;
}

public static function getView(){
    return self::$view;
}

public static function getAssetsSiteImg($image){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        self::$root = '';   
    }
    echo self::$root.'/assets/site/img/'.$image;
}

public static function getAssetsSiteJs($js){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        self::$root = '';   
    }
    echo self::$root.'/assets/site/js/'.$js;
}

public static function getAssetsLibJs($js){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        self::$root = '';   
    }
    echo self::$root.'/assets/libs/js/'.$js;
}

public static function getAssetsLib($js){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        self::$root = '';   
    }
    echo self::$root.'/assets/libs/'.$js;
}

public static function getRoot(){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        return '';  
    }else{
        return self::$root;
    }
}

public static function getRootPageAdmin($page){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        return "/coordenacao/".$page;   
    }else{
        return self::$root."/coordenacao/".$page;
    }
}

public static function getRootPage($page){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        echo "/coordenacao/".$page;
    }else{
        echo self::$root."/coordenacao/".$page;
    }
}

public static function getRootPageSite($page){
    self::$root = ''.dirname( $_SERVER["PHP_SELF"] ).'';
    if(self::$root=='/'){
        echo "/".$page; 
    }else{
        echo self::$root."/".$page;
    }
}

public static function redirectPage($pagina){
    $pagina = ViewControl::getRoot()."/coordenacao/".$pagina;
    exit ('<script>top.location="'.$pagina.'"</script>');
}

public static function redirectPageSite($pagina){
    $pagina = ViewControl::getRoot()."/".$pagina;
    exit ('<script>top.location="'.$pagina.'"</script>');
}

public static function redirectPageAdmin($pagina){
    $pagina = ViewControl::getRoot()."/coordenacao/".$pagina;
    exit ('<script>top.location="'.$pagina.'"</script>');
}

public static function getDominio(){
    $dominio = $_SERVER['PHP_SELF'];
    $dominio = explode("/", $dominio);
    $dominio = array_slice($dominio, 1);
    return $dominio[0];
}

public static function showView(){

    $request = new FriendlyURL();
    $view = new View();
    $view -> setControl($request -> control);
    $view -> setParametros($request -> params);
    $view -> setUser(Sessao::getUsuario());
    self::$view = $view;

    if($view -> getParametros() == null){
        $primeiroParametro = null;
    }else{
        $primeiroParametro = $request -> params[0];
    }

    if( ($view -> getControl() == Constants::ADMIN_DIR_NAME) && ($primeiroParametro == null) || ($view -> getControl() == Constants::ADMIN_DIR_NAME) && ($primeiroParametro == '') || ($view -> getControl() == Constants::ADMIN_DIR_NAME) && ($primeiroParametro == 'index') || ($view -> getControl() == Constants::ADMIN_DIR_NAME) && ($primeiroParametro == 'index.php') ){

        $view -> setControl('index');
        $old_array = $view -> getParametros();
        $new_array = array();
        $i = -1;
        foreach ($old_array as $parametro) {
            if($i != -1){
                $new_array[$i]=$parametro;
            }
            $i++;
        }

        if($view -> getControl()=='index'){
            $view -> setControl('home');
        }

        $view -> setParametros($new_array);
        $filename = Constants::ADMIN_CAMINHO.$view -> getControl().'.php';

    } else if( ($view -> getControl() == Constants::ADMIN_DIR_NAME) && ($view -> getParametros() != null) ){

        $old_array = $view -> getParametros();
        $new_array = array();
        $i = -1;
        foreach ($old_array as $parametro) {
            if($i != -1){
                $new_array[$i]=$parametro;
            }
            $i++;
        }
        if($old_array[0]=='msg'){
            $view -> setControl('index');
        }else{
            $view -> setControl($old_array[0]);
        }

        if($view -> getControl()=='index'){
            $view -> setControl('home');
        }

        $view -> setParametros($new_array);
        $filename = Constants::ADMIN_CAMINHO.$view -> getControl().'.php';

    } else {
        $filename = Constants::SITE_CAMINHO.$view -> getControl().'.php';
    }

    if(file_exists($filename)){
        include $filename;
    }else{
        //ViewControl::redirectPageSite(Page::PAGE_404);
    }

}

}

Next error:

Fatal error: Class 'ViewController' not found in C:\xampp\htdocs\blogando\view\site\index.php on line 3

 $thisView = ViewController::getView() 

Note: I'm using php 7, I've already researched it and found nothing about it.

I wrote the following code snippet, however, I did not resolve it:

   function __autoload($ViewController) {
       if(file_exists($ViewController . '.php')) {
           require_once ($ViewController . '.php');
   }
   else {
    throw new Exception("Unable to load $ViewController");
     }
  }

   try {
     $class = new ViewController();
   } catch (Exception $e) {
       echo $e -> getMessage() , "\n";
   }
    
asked by anonymous 28.04.2016 / 14:53

0 answers