Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/02/2010, 09:16
Avatar de mackiechan
mackiechan
 
Fecha de Ingreso: junio-2009
Ubicación: Maracay, Venezuela
Mensajes: 51
Antigüedad: 14 años, 9 meses
Puntos: 12
Clase para templates

Buenos días,

Estuve revisando el foro a ver si encontraba solución al problema que tengo y no encontre aunque se muy bien que tipo de error me esta dando o el porqué, asi que tuve que crear el tema :/

El asunto es que conseguí una clase llamada clase_plantilla.php:

Código PHP:
<?php
class Plantilla{
        function 
plantilla($template_file,$tema){
                
$this->html_plantilla RAIZ_.'/temas/'.$tema.'/'$template_file '.html';
        }
        
        function 
asigna_variables($vars){
                
$this->vars= (empty($this->vars)) ? $vars $this->vars $vars;
        }
        
        function 
muestra(){
                if (!(
$this->fd = @fopen($this->html_plantilla'r'))) {
                        
sostenedor_error('error al abrir la plantilla ' $this->html_plantilla);
                } else{
                        
$this->template_file fread($this->fdfilesize($this->html_plantilla));
                        
fclose($this->fd);
                        
$this->mihtml $this->template_file;
                        
$this->mihtml str_replace ("'""\'"$this->mihtml);
                        
$this->mihtml preg_replace('#\{([a-z0-9\-_]*?)\}#is'"' . $\\1 . '"$this->mihtml);
                        
reset ($this->vars);
                        while (list(
$key$val) = each($this->vars)) {
                                $
$key $val;
                        }
                        eval(
"\$this->mihtml = '$this->mihtml';");
                        
reset ($this->vars);
                        while (list(
$key$val) = each($this->vars)) {
                                unset($
$key);
                        }
                        
$this->mihtml=str_replace ("\'""'"$this->mihtml);
                        echo 
$this->mihtml;
                }
        }
}
?>

La cual uso en:

Código PHP:
<?php

//al Pasar como parametro holaMundo, asumimos que en la carpeta plantillas existe un archivo de nombre holaMundo.tpl
    
$Contenido=new Plantilla('index',$tema);
    
$Contenido->asigna_variables(array(
            
'titulo' => $titulo,
        
'raiz'   => RAIZ_,
        
'login' => include(RAIZ_.'/modulos/login.php')
    ));

//$ContenidoString contiene nuestra plantilla, ya con las variables asignadas, fácil no?
    
$ContenidoString $Contenido->muestra();
    echo 
$ContenidoString;
?>
Y mi archivo index.html sería:

Código:
<html>
<head>
<title>{titulo}</title>
<script language="JavaScript" type="text/javascript" src="{raiz}/libreria/js/jquery-1.4.1.min.js"></script>
<link href="{raiz}/temas/predeterminado/css/base.css" rel="stylesheet" type="text/css" />
</head>
<body>


<div id="login">

{login}


</div>


</body>
</html>

El llamado al {titulo} de la pagina y a la direccion {raiz} funcionan perfecto, el problema ocurre cuando quiero hacer un include al llamar mi modulo login.php, la inclusión se efectua y muestra mi modulo, y funciona perfecto todo mi php, pero la ubicación de este ignora totalmente la que le asigne, es decir yo le digo que aparezca en la capa <div id=login>{login}</div> y en la pagina final al ejecutar mi index.php me sale todo el modulo de login encima de la etiqueta <html>.

Sera que alguien tiene idea de que ocurre? Y_Y