
-Estoy tratando recien el tema de Sistema de Plantillas especificamente el patrón de diseño MVC(modelo-Vista- Controlador). En primer lugar tengo mi clase VO(value object . que representa a la trabla con sus columnas respectivas) el codigo es:
Código PHP:
Ver original
<?php class DetalleVO { public $art_cod; public $art_nom; public $art_pre; public $art_can; public $total; public function __construct($cod, $nom, $pre, $can, $tot){ $this->art_cod = $cod; $this->art_nom = $nom; $this->art_pre=$pre; $this->art_can = $can; $this->total=$tot; } } ?>
Ahora tengo el DAO (data acces object) que representa la persistencia. Dada un numero de factura que me devueva los productos que contiene factura
Código PHP:
Luego tengo un controlador que se encarga de las dos capas anteriores y que trabaja con la plantillaVer original
<?php require_once DIRECTORIO_RAIZ . "/clases/util/Conexion.class.php"; require_once DIRECTORIO_RAIZ . "/clases/util/DAOExcepcion.class.php"; require_once DIRECTORIO_RAIZ . "/clases/vo/DetalleVO.class.php"; class DetalleDAO { public function obtener($fac_num){ try{ $cnx=Conexion::getInstancia(); $fac_num=$cnx->dbLink->qstr($fac_num); $query="select d.art_cod, a.art_nom, a.art_pre,d.art_can, a.art_pre*d.art_can as total"; $query.=" from articulos a, fac_deta d"; $query.= " where a.art_cod=d.art_cod and fac_num='%".$fac_num."%' group by d.art_cod, a.art_nom, a.art_pre,d.art_can;"; $resultSet=$cnx->dbLink->Execute($query); if(!$resultSet){ throw new DAOExcepcion($cnx->dbLink->ErrorMsg()); }else{ while(!$resultSet->EOF){ $resultado[]=new DetalleVo($resultSet->fields['art_cod'], $resultSet->fields['art_nom'], $resultSet->fields['art_pre'], $resultSet->fields['art_can'], $resultSet->fields['total']); $resultSet->MoveNext(); } } $resultSet->Close(); $cnx->dbLink->Close(); }catch(ConexionExcepcion $e){ throw new DAOExcepcion($e->getMessage()); }catch(DAOExcepcion $dao){ throw new DAOExcepcion($dao->getMessage()); } return $resultado; } } ?>
Código PHP:
y por ultimo la plantilla que muestra los datosVer original
<?php require_once "conf.php"; require_once "./clases/dao/DetalleDAO.class.php"; $tpl = new Savant3(); $dao = new DetalleDAO(); switch ($accion){ case 'detalle': try{ $vo=$dao->obtener($_POST['fac_num']); $tpl->detalle=$vo; $tpl->display('/plantillas/detalle_listar.tpl.php'); }catch(DAOExcepcion $e){ $tpl->mensaje_error=$e->getMessage(); $tpl->display('/plantillas/detalle_listar.tpl.php'); return; } return; break; default: try { $tpl->display('/plantillas/detalle_listar.tpl.php'); } catch(DAOExcepcion $e){ print "Problemas con su red."; } return; } ?>
Código PHP:
Ver original
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="detalles.php"> <input type ="hidden" name="accion" value="detalle"/> <p><strong><em>Detalle de Una Factura</em></strong></p> <p>Factura <label> <input type="text" name="fac_num" /> </label> <label> <input type="submit" name="button" id="button" value="Buscar" /> </label> </p> </form> <table width="399" border="1" cellspacing="1" cellpadding="3"> <tr> <th width="64" scope="col">Codigo</th> <th width="104" scope="col">Descripcion</th> <th width="73" scope="col">Precio Unitario</th> <th width="56" scope="col">Cantidad</th> <th width="54" scope="col">Total</th> </tr> <tr> <td><?php print $vo->art_cod;?></td> <td><?php print $vo->art_nom;?></td> <td><?php print $vo->art_pre;?></td> <td><?php print $vo->art_can;?></td> <td><?php print $vo->total;?></td> </tr> <?php }}?> </table> <p> Total de Importe <label> <input type="text" name="textfield2" id="textfield2" readonly="readonly" /> </label> </p> <p> </p> </body> </html>
Luego que ingreso el número de factura y envio el formulario me salen dos errores:
Código HTML:
Ver original
Notice: Undefined property: Savant3::$detalle in C:\wamp\www\Eclipse.projects\ProyectoVentas\plantillas\detalle_listar.tpl.php on line 30 Warning: Invalid argument supplied for foreach() in C:\wamp\www\Eclipse.projects\ProyectoVentas\plantillas\detalle_listar.tpl.php on line 30
Como les repito soy novato con el trabajo de plantillas, por favooor que alguien me ayude please!
pues el detalle esta en que sepas utilizar Savant3 ve a la pagina de dicha clase...
