3
I have the following problem, I am using an MVC model for a CMS in PHP study, but I would like it to be possible to use themes, for this I created a configuration variable that stores the theme name to test, and when I use my controller to call my view, is as follows:
$this->render('view_posts', $parametros);
In this role I pass to view which I will use and vector $parametros
, that contains page title, description, content, etc. My render() function looks like this:
private function render($view, $parametros)
{
require_once(_APP_ROOT . '/view/' . $view.'.php');
}
If I try to get the vector $parametros
in view_posts.php
works smoothly, but as I said I wanted it to support themes, so on view_posts.php
I have a require_once
with the theme name and the corresponding page.
require_once(_APP_ROOT . '/tema/' . _TESTE_TEMA . 'index_view.php');
And in the index_view.php
of my theme it does not recognize the vector $parametros
.
How can I solve this problem? I believe it’s an easy problem to solve but I’m already a little blind in this project and I can’t find a solution.
One detail I’d like to quote is that I’m not using any framework, and would not like to use because it is a study CMS.
is displayed error "Notice: Undefined variable: parameters" or some other?
– Pedro Sanção
Exactly, as if I had never defined.
– Renan Cavalieri
no idea of possible cause, but use the function
get_defined_vars()
in a debug can help you– Pedro Sanção
I found this "When you included the template file, you Did the Operation WITHIN the header Function, Thus making all $page variable in the template file referring to the local $page variable in the header Function, which apparently is not declared/defined." - http://stackoverflow.com/questions/1962321/undefined-variable-after-using-require-once - But I still do not know how I will apply to my case, because when it comes to MVC, my views are "dumb", I do not know how I would pass this to my theme.
– Renan Cavalieri
I’ll give you a hint that might be useful for your purpose: Try this library (it’s not a framework, it’s just a plugin) -> http://platesphp.com/
– Ivan Ferrer