0

Estrutura do meu projeto

inserir a descrição da imagem aqui

No meu arquivo Imports.php tenho seguinte código:

//UTIL
require_once 'util/Constants.php';
require_once 'util/Page.php';


//Control
require_once 'control/ViewController.php';

//View
require_once 'view/View.php';

No meu arquivo start.php tenho seguinte código:

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

No meu class View.php tenho seguinte código:

class View {

private $control;
private $parametros;
private $user;
private $modulo = null;

function View() {
}

public function getControl() {
    return $this -> control;
}

public function setControl($control) {
    $this -> control = $control;
}

public function getParametros() {
    return $this -> parametros;
}

public function setParametros($parametros) {
    $this -> parametros = $parametros;
}

public function getUser() {
    return $this->user;
}

public function setUser($user) {
    $this->user = $user;
}

public function hasPermission(){
    if($this->user!=null){
        if($this->modulo!=null){
            if(strcmp($this->modulo, $this->user->getTipo())!=0){
                return false;
            }
        }
        return true;
    }
    return false;
}

public function setModulo($modulo){
    $this->modulo =  $modulo;
}

public function getModulo(){
    return $this->modulo;
}

}

No meu class ViewController.php tenho seguinte código:

class ViewController {

private static $instance = null;
private static $root = null;
private static $currentUrl = null;
private static $view;

private function __construct() {}

public static function getInstance() {

    //Contruir Url Atual
    $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);
    }

}

}

Erro seguinte:

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

 $thisView = ViewController::getView() 

Obs: Estou utilizando o php 7, já dei uma pesquisada e não encontrei nada em relação a isso.

escrevi seguinte trecho de código mesmo assim não resolvi:

   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";
   }
10
  • No require, tente usar $_SERVER['DOCUMENT_ROOT']."/nome_arquivo"; pra ver no que dá 28/04/2016 às 13:17
  • Não deu certo.. 28/04/2016 às 13:21
  • Você iniciou ela? Porque ali você montou ela apenas, fez a inicialização dela? 28/04/2016 às 13:22
  • $obj = new ViewController(); 28/04/2016 às 13:24
  • 2
    Já considerou utilizar uma função de __autoload() na sua aplicação? 28/04/2016 às 13:51

0

Você deve fazer log-in para responder a esta pergunta.

Pesquise outras perguntas com a tag .