Hello everyone. I was reflecting on the existence of a structure relationship step in my project.
The organization of my project is as follows:
[1]Whenaccessingthepage,theusercanaccesseitherthenormaladdress(egcurso.php
)orparameters(egcurso.php?curso=sistema_informacao
).Inthecaseofaccessbynormaladdress,itisusuallyaccessedbythebuttonthathasthefileindex.php
.Fromtheuseractionthecurso.php
checkstoseeifanyparametershavebeenpassed,whichisusuallypassedviaajax
instep[3].
[2]Assoonasthecurso.php
filecompletestheparametercheck,itcallsthefileview_curso.php
.Theaddresswillremainas.../curso.php
[3]Throughuseractions,javascriptdoesPOSTviaajax
tocurso.php
fileandoneoftheparametersthatissentiscalledopcao
,socurso.php
knowswhichcontrollerfunctionshouldcall,step[4].
functionpesquisar(){varcurso=documento.getElementById("id_curso").value;
$.ajax({
type: "POST",
url: "curso.php",
data: {
"curso": curso,
'opcao': 'pesquisar_disciplinas'
}
});
}
[4] The controller checks the action and if the parameters are correct it calls the class that will execute that action.
[5] In this example, the action being a select, then the controller calls the model_curso.php
.
[6] The model_curso.php
returns the result for the controller.
[7] The controller checks, and in this example it calls the file view_painel_curso.php
with the results of model_curso.php
.
The question I have is whether there really is a need for the curso.php
file to exist.
Basically, the file curso.php
is an intermediary of the view and the controller, and has as a function to make a filter of what is being requested by the view and to pass to the controller that then dictates who will execute.
Is there any variation of the MVC that uses this architecture that I'm using or can we say that it still is the MVC? Do you use some similar structure?
course.php
<?php
# Importar bibliotecas e classes
require_once "../require.php";
# Importar controlador
require_once "./controllers.php";
// mostrar exceções de banco de dados
$APP->getDBLink()->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
# exigir que usuário esteja logado
$APP->requireLoggedUser(true);
# Inicializar o objeto controlador
$Ctrl = new \curso\Controller($APP);
# método da requisição
$reqmethod = $_SERVER['REQUEST_METHOD'];
if( $reqmethod == "POST" ) {
$opcao = filter_input(INPUT_POST, "opcao");
// salvar disciplina
if ($opcao == "salvar_curso"){
$Ctrl->salvarCurso(['POST' => $_POST]);
// pesquisar curso
} elseif($opcao == "pesquisar_disciplinas"){
$Ctrl->getDisciplinas($_POST);
}
} else {
$curso = filter_input(INPUT_GET, "curso");
$disciplina = filter_input(INPUT_GET, "disciplina");
if(isset($curso)) {
$APP->requireLoggedUser(true);
# Define qual parte do controlador vai usar
$content = function() use($Ctrl) {
//
$Ctrl->pesquisar(['GET' => $_GET ]);
};
} else {
$content = function() use($Ctrl){
$Ctrl->indexAction('view_curso');
};
}
# qual template HTML
$qual_template = 'basico2';
# título da página
$title = 'Cursos Faculdade';
$options['css']['files'][] = '<link href="static/estilos.css" rel="stylesheet" type="text/css">';
$options['js_files'][] = '<script src="./static/assets/moment/moment.js"></script>';
$options['js_files'][] = '<script src="./static/assets/moment/moment-with-locales.js"></script>';
$options['js_files'][] = '<script type="text/javascript" src="static/curso.js"></script>';
$options['favicon'] = '<link id="favicon" rel="shortcut icon" href="/static/imgs/icone.png" type="text/css" />';
# chamar o template
$APP->printTemplate( $qual_template, $title, $content, $options );
}
?>