1
Hey there, guys. I was reflecting on the existence of a relationship step of the structure of my project.
The organization of my project is as follows:
[1 ] When accessing the page the user can access both the normal address (ex. curso.php
) or with parameters (ex. curso.php?curso=sistema_informacao
). In the case of access by normal address, it is usually accessed by the button you have in the file index.php
.
From the action of the user the file curso.php
makes a check if any parameter has been passed, where it is normally passed via ajax
in step [3].
[2] As soon as the file curso.php
finishes checking parameters, it calls the file view_curso.php
. The address will remain as .../curso.php
[3] Through user actions javascript makes POST via ajax
to the archive curso.php
and one of the parameters that is sent is called opcao
, thus the curso.php
knows which controller function to call, step [4].
function pesquisar(){
var curso = 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 perform 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 to 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 to exist the file curso.php
.
Basically, the file curso.php
is a view and controller intermediary, and has the function to filter what is being requested by the view and pass to the controller that then dictates who will perform.
Is there any variation of MVC that uses this architecture that I’m using or can we say that it’s still MVC? Do you use any similar structure?
php course.
<?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 );
}
?>