Hola a todos, tengo un problema al pasar un array por la clase de templates.
Esta es la clase:
Código PHP:
Ver original<?php
class Plantilla{
function __construct($template_file){
$this->tpl_file = 'plantillas/' . $template_file . '.tpl';
}
function asigna_variables($vars){
$this->vars= (empty($this->vars)) ?
$vars : $this->vars . $vars; }
function muestra(){
if (!($this->fd = @fopen($this->tpl_file, 'r'))) { sostenedor_error('error al abrir la plantilla ' . $this->tpl_file);
} else{
$this->template_file = fread($this->fd, filesize($this->tpl_file)); $this->mihtml = $this->template_file;
$this->mihtml = str_replace ("'", "\'", $this->mihtml); $this->mihtml = preg_replace('#\{([a-z0-9\-_]*?)\}#is', "' . $\\1 . '", $this->mihtml); while (list($key, $val) = each($this->vars)) { $$key = $val;
}
eval("\$this->mihtml = '$this->mihtml';"); while (list($key, $val) = each($this->vars)) { }
echo $this->mihtml;
}
}
}
?>
Entonces, cuando asigno las variables a pasar al documento html, sería algo así :
Código PHP:
Ver originalrequire('_clases/clase_plantilla.php');
$profileTemplate=new Plantilla('profile');
$profileTemplate->asigna_variables(array( "titulo" => "algo"
));
$ContenidoString = $profileTemplate->muestra();
echo $ContenidoString;
Entonces, en el documento tpl:
Lo de arriba imrpimiría "algo", ya que es el valor que le di a la variable
Pero, ¿que tal si quiero pasar arrays?, tal vez consultas de sql, como por ejemplo:
Código PHP:
Ver original$_q=mysql_query("SELECT * FROM tabla WHERE id_usuario = 1"); $_queryUser = $_query['user'];
}
require('_clases/clase_plantilla.php');
$profileTemplate=new Plantilla('profile');
$profileTemplate->asigna_variables(array( "nombres" => $_queryUser
));
$ContenidoString = $profileTemplate->muestra();
echo $ContenidoString;
Pero en el documento TPL solo me sale un solo resultado, entonces necesito no solo pasar variables, sino ARRAYS, pero no sé como hacerlo.
¿Alguien me da una mano?
Gracias desde ya.