Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/02/2012, 12:05
Avatar de GatorV
GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Respuesta: MVC:¿ Como cargar las plantillas ?

Ah ya entendí, pues sí es buena práctica y no veo porque no lo puedas hacer, en lugar de hacer el include directo podrías cambiar tu método por algo así:
Código PHP:
Ver original
  1. function render($name, $vars) {
  2.         $path = __SITE_PATH . '/views' . '/' . $name . '.php';
  3.  
  4.         if (file_exists($path) == false)
  5.         {
  6.                 throw new Exception('Template not found in '. $path);
  7.                 return false;
  8.         }
  9.  
  10.         // Load variables
  11.         foreach ($vars as $key => $value)
  12.         {
  13.                 $$key = $value;
  14.         }
  15.  
  16.         ob_start();
  17.         include ($path);
  18.         return ob_get_clean();
  19. }

Entonces en tu controller podrías hacer:
Código PHP:
Ver original
  1. $productos = $this->registry->template->render('productos', $productos_array);
  2. echo $this->registry->template->render('index', $productos);

Saludos