It is a scheme that I am inventing since in this project I will not go by framework because it is very simple,
Working with MVC in the Framework (Codeigniter),
But I do not have a separate Model class with load (only as a file), it's always an extension of the Controller, so I'll create my controller, give them a name in the boot configuration and I want load to load all these are in the vector, along with the model of each one.
What is missing, is that it automatically give the load with the $ variable name, the name of the Controller being lowercase, and the new = Class; instead of the word "Class" I want the name of the file that is the same as the class name of the Controller.
In short, auto load, but already give the new command to initialize the class, it is giving error.
Code:
<?php
/* ------------------------------------------------------ *
* Configuração do php
* ------------------------------------------------------ */
ini_set('display_errors', 1);
/* ------------------------------------------------------ *
* Configuração inicial do Sistema
* ------------------------------------------------------ */
$base_url = 'http://localhost:8081/bitbucket/16.4.2/';
$index_page = 'index.php';
$charset = 'ISO-8859-1';
$autoload = 1;
/* ------------------------------------------------------ *
* Configuração do autoload
* ------------------------------------------------------ */
$autoload['Controller'] = array(
"Cliente",
"Administrador",
"Ticket",
"Notificacao"
);
$autoload['lib'] = array("buscaCep","fup");
/* ------------------------------------------------------ *
* Carrega a configuração
* ------------------------------------------------------ */
spl_autoload_register(function ($nome) {
global $base_url;
foreach($autoload['Controler'] as $elemento):
if ($elemento == $nome):
$Controller = $base_url."Controller/".$nome.".Controller.php";
if(is_file($Controller)):
$Model = $base_url."Model/".$nome.".Model.php";
if(is_file($Model)):
include_once("$Model");
endif;
include_once("$Controller");
${strtolower($nome)} = new {$nome};
endif;
endif;
$x++;
endforeach;
});
/* ------------------------------------------------------ *
* Inicializar Controllers com o comando ''$nomedoobj = new Controller';
* ------------------------------------------------------ */
//$administrador = new Administrador();
//$ticket = new Ticket();
foreach($autoload['Controler'] as $elemento):
${strtolower($elemento)} = new {$elemento};
endforeach;
?>
Line with error is:
Parse error: syntax error, unexpected '{' in /home/andre/public_html/bitbucket/16.4.7/conf.php on line 49
Code:
${strtolower($nome)} = new {$nome};
The name of the file where the class is Controller / Admin.Controller.php
And here's the code:
<?php
class Administrador extends AdministradorModel {
function helloworld(){
echo "<h1>Hello World</h1>";
}
}
I imagine that the code I typed in the line with error would be the theory of how I want it to work, of course, it's wrong, but how could it be ?