Hello everyone. I have some questions:
We assume that I want to display a table of files that are registered in the database.
In my FilesController.php, I have:
public function carregarLista($status){
$this->arquivosModel->setStatus($status);
$this->arquivosModel->setServidorCriacao($_SESSION['ID']);
$listaArquivos = $this->arquivosModel->getListaArquivosStatus();
$titulo = ($status=='ATIVO') ? "Meus Arquivos Ativos" : "Meus Arquivos
Inativos";
$this->arquivosView->setTitulo($titulo);
$this->arquivosView->setTipo("listagem");
$this->arquivosView->setLista($listaArquivos);
$this->arquivosView->carregar();
}
In myModelFiles, the function getListStatus (), I have:
public function getListaArquivosStatus(){
$this->conectar();
$resultado = mysqli_query($this->conexao,
"SELECT
a.ID, a.DS_TIPO, a.DT_CRIACAO, a.ID_SERVIDOR_CRIACAO, a.DS_STATUS,
a.DS_ANEXO,
s1.DS_NOME NOME_SERVIDOR_CRIACAO,
s2.DS_NOME NOME_SERVIDOR_DESTINO
FROM tb_arquivos a
INNER JOIN tb_servidores s1 ON a.ID_SERVIDOR_CRIACAO = s1.ID
INNER JOIN tb_servidores s2 ON a.ID_SERVIDOR_DESTINO = s2.ID
WHERE a.DS_STATUS = '".$this->status."'
AND (a.ID_SERVIDOR_CRIACAO = ".$this->servidorCriacao."
OR a.ID_SERVIDOR_DESTINO = ".$this->servidorCriacao.") ORDER BY
a.DT_CRIACAO desc
");
$listaArquivos = array();
While($row = mysqli_fetch_array($resultado)){
array_push($listaArquivos, $row);
}
$this->desconectar();
return $listaArquivos;
}
My question is:
How can I show this data (which passes through the controller) so that I do not use the database field names in the view construction?
For example: Let's say I want to show the file type in a table. The way I submitted the data, it would look like:
<td><?php echo $arquivo['DS_TIPO'] ?></td>
I do not want the view to use the database fields, because a priori the view does not know anything about the model. Another reason is that if I change a name in the database, in maintaining the code I would only have to move the model, because it is he who takes care of the bank.
Is there any problem with the print view like this? Is there any way to leave these fields only in the model and bring them otherwise to the view?
Hugs!