Jump to content
Fórum Script Brasil
  • 0

Fatal error: Uncaught Error: Class


Question

Boa noite.

Estou desenvolvendo uma aplicação em php para estudos em MVC onde tenho as seguintes classes:

Index.php

<?php
 
define('APP_ROOT', 'aula');
 
require_once 'helper/Bootstrap.php';
 
use lib\System;
 
$System = new System;
 
$System->Run();

Bootstrap.php

<?php
 
spl_autoload_register(function($class){
$file= str_replace('\\', '/', $class);
 
if(file_exists($file)){
require_once $file;
}
});

System.php

<?php
 
namespace lib;
 
class System extends Router{
private $url;
private $exploder;
private $area;
private $controller;
private $action;
private $params;
private $runController;
 
public function __construct()
{
$this->setUrl();
$this->setExploder();
$this->setArea();
$this->setController();
$this->setAction();
$this->setParams();
}
 
private function setUrl(){
$this->url = isset($_GET['url']) ? $_GET['url'] : 'home/index';
}
 
private function setExploder(){
$this->exploder = explode('/', $this->url);
}
 
private function setArea(){
foreach($this->routers as $key => $value){
if($this->onRaiz && $this->exploder[0] == $key){
$this->area = $value;
$this->onRaiz = false;
}
}
 
$this->area = empty($this->area) ? $this->routerOnRaiz : $this->area;
 
if (!defined('APP_AREA')) {
defined('APP_AREA', $this->area);
}
}
 
public function getArea(){
return $this->area;
}
 
private function setController(){
$this->controller = $this->onRaiz ? $this->exploder[0] :
(empty($this->exploder[1]) || is_null($this->exploder[1]) || !isset($this->exploder[1]) ? 'home' : $this->exploder[1]);
}
 
public function getController(){
return $this->controller;
}
 
private function setAction(){
$this->action = $this->onRaiz ?
(!isset($this->exploder[1]) || is_null($this->exploder[1]) || empty($this->exploder[1]) ? 'index' : $this->exploder[1]) :
(!isset($this->exploder[2]) || is_null($this->exploder[2]) || empty($this->exploder[2]) ? 'index' : $this->exploder[2]);
}
 
public function getAction(){
return $this->action;
}
 
private function setParams(){
if($this->onRaiz){
unset($this->exploder[0], $this->exploder[1]);
}else{
unset($this->exploder[0], $this->exploder[1], $this->exploder[2]);
};
 
if(end($this->exploder) == null){
array_pop($this->exploder);
};
if(empty($this->exploder)){
$this->params = array();
}else{
foreach ($this->exploder as $value) {
$params[] = $value;
}
$this->params = $params;
};
}
 
public function getParams($indice){
return isset($this->params[$indice]) ? $this->params[$indice] : null;
}
 
private function validarController(){
if(!(class_exists($this->controller))){
header('HTTP/1.00 404 Not Found');
define('ERROR', 'não foi localizado o Controller' . $this->controller);
include("content/[$this->area]/shared/404_error.phtml");
};
}
 
private function validarAction(){
if(!(method_exists($this->runController, $this->action))){
header('HTTP/1.00 404 Not Found');
define('ERROR', 'não foi localizado o Controller' . $this->action);
include("content/[$this->area]/shared/404_error.phtml");
}
}
 
public function Run(){
$this->runController = 'controller\\' . $this->area . '\\' . $this->controller . 'Controller';
 
$this->validarController();
 
$this->runController = new $this->runController();
 
$this->validarAction();
 
$act = $this->action;
 
$this->runController->act();
}
}

A arvore das pastas estao da seguinte maneira:

image.png.d7674cb8a67200adbfee4cd3afa27cd3.png

 

Ao executar a aplicação da a seguinte mensagem:

Fatal error: Uncaught Error: Class 'lib\System' not found in C:\xampp\htdocs\aula\index.php:10 Stack trace: #0 {main} thrown in C:\xampp\htdocs\aula\index.php on line 10

Fiz algumas pesquisas e muitas delas falaram que era a forma que estava "instanciando" a classe System, já tentei "use", "require_once" e "require" e com isso apenas mudou  mensagem de erro, saberiam o que mais posso fazer para tentar sanar esse erro?

Obs.: Na index.php quando vou dar o "new" já tentei chamar a classe com e sem parentes (new System e new System() ).
 

Muito Obrigado....

 

 

 

 

Link to post
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148692
    • Total Posts
      644524
×
×
  • Create New...