1
I have a controller that will pass display information to a view, this information will be objects, and they will be passed in array.
namespace app\controllers\conteudo;
class index
{
public function get_index()
{
// Supondo que eu já tenha os objetos $usuario e $publicacao instanciados e populados.
$args = array
(
$usuario,
$publicacao
);
$view = new \app\views\view();
$view->pagina('publicacao', $args);
}
}
And a function that will load a template page and display this information.
namespace app\views;
class view
{
private $template;
public function pagina($arquivo, $args = null)
{
require(getcwd() . "/app/views/templates/{$this->template}/{$arquivo}.php");
}
}
In my template file, I can access $args[0] and $args[1], but I would not like to have access to these variables in this way, but how $usuario and $publicacoes.
I could set variables to pick up these values, but the problem is that the parameters that will be passed are uncertain, so if I pass $categoria by an array, I want to have access to $categoria in the template file.
How to do this?
A
extract()in$argsis an option the indices will turn variable. There must be other ways to solve this.– rray
It’s a similar question: include, require inside functions methods
– rray