I'm building a small MVC application with PHP
, following directory structure:
-
controllers /
-
views / (Views files)
In each controller, I pass an instance of the VIEW object with an array with data to be able to use it in the view file, example:
New View('Busca','header', 'footer', $viewParams );
Note: these 2 parameters that I have passed (header and footer), will be included together of the view, example:
Include Header;
Include Busca ( **a view que passei por parâmetro** );
Include Footer;
So far so good, I can pass the data to any view, from its controller, but how I made my site with HEADER and FOOTER, and these files are not in the rule of my view that is to get VIEW files by folders, for example:
Directory Structure
Views/Busca/
- Index.phtml
Views/Error/
- Index.phtml
Como HEADER e FOOTER, estão em:
- Views/Header.phtml
- Views/Footer.phtml
I just need to change values dynamically in my header, the only way to do this is in every controller, put the same code and pass by parameter to my view, example :
BuscaAction()
{
$setParams = array('title_page' => 'Título do Site');
$view = New view('Busca','header','footer',$setParams);
$view->render();
}
ErrorAction(){
$setParams = array('title_page' => 'Título do Site');
$view = New view('Error','header','footer',$setParams);
$view->render();
}
Instead, I would like to pass this information in a unique way and can dynamically change, as if it were a normal controller, passing through the controller constructor is a solution?