He reducido un proyecto en algunos archivos bases. El problema que tengo que es el proyecto trabaja con plantillas Smarty 2.x y al pasarlo a Smarty 3 no sale un error. El problema es pasar todo el código a PHP 5 pues Smarty 3 solamente funciona con PHP5.
Me gustaría revisarlo con ustedes a fin de comprender mejor todo el tema. Primero voy a subir el código ok?
Esta es la estructura de las carpetas.
index.php
config.php
configure.php
config_db.php
Plantilla.class.php
ProductoDAO.class.php
ProductoVO.class.php
get_articulos.tpl.php
Y la base de datos es esta:
Al ejecutarlo con Smarty 2.x funciona.
Pero al cambiar en configure.php para que funcione el smarty3, sale el error.
Agradeceré me ayuden con lo este código.
Gracias.
Me gustaría revisarlo con ustedes a fin de comprender mejor todo el tema. Primero voy a subir el código ok?
Esta es la estructura de las carpetas.
index.php
Código:
<?php
require_once "./config.php";
$tpl = new Plantilla();
$dao = new ProductoDAO();
$lista = $dao->listar();
$tpl->assign("lista", $lista);
$tpl->display('get_articulos.tpl.php');
?>
Código:
<?php
define("APP_BASEDIR", dirname(__FILE__));
require_once('includes/configure.php'); //setting parameters
require_once('includes/config_db.php'); //setting data base
?>
Código:
<?php
//---- SUBFOLDERS
define('DIR_CSS', APP_BASEDIR. '/css/');
//---- LIBRARYS ----- //
define('SMARTY_BASEFILE', APP_BASEDIR . '/lib/Smarty-2.6.14/Smarty.class.php');
//define('SMARTY_BASEFILE', APP_BASEDIR . '/lib/Smarty-3.1.15/Smarty.class.php');
//*define('ADODB_BASEFILE', APP_BASEDIR . '/lib/adodb-492/adodb.inc.php');
define('ADODB_BASEFILE', APP_BASEDIR . '/lib/adodb518/adodb.inc.php');
//---- PATH OBJECTS
require_once APP_BASEDIR . "/clases/vo/ProductoVO.class.php";
require_once APP_BASEDIR . "/clases/dao/ProductoDAO.class.php";
require_once APP_BASEDIR . "/clases/util/ConexionDB.class.php";
require_once APP_BASEDIR . "/clases/util/Plantilla.class.php";
//---- SETTING
ini_set('session.gc_maxlifetime','1800'); // 30 minutos
ini_set('error_reporting', E_ALL);
session_start();
?>
Código:
<?php
//------ DATABASE CONNECTION ------//
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_KEY' , 'clave');
define('DB_DATA', 'tienda');
define('DB_TYPE', 'mysql');
?>
Código:
<?php
include_once SMARTY_BASEFILE;
class Plantilla extends Smarty {
function Plantilla() {
$this->template_dir = APP_BASEDIR .'/plantillas/templates/';
$this->compile_dir = APP_BASEDIR .'/plantillas/templates_c/';
$this->config_dir = APP_BASEDIR .'/plantillas/configs/';
$this->cache_dir = APP_BASEDIR .'/plantillas/cache/';
}
}
?>
Código:
<?php
class ProductoDAO {
function ProductoDAO() {
}
function listar(){
$query = "SELECT id_producto, id_categoria, nombre, descripcion, precio, stock, importancia, imagen FROM producto order by id_producto";
$BD = new ConexionDB();
$recordSet = $BD->dbLink->Execute($query);
if (!$recordSet){
Debug::println("No se pudo ejecutar la consulta listar: " . $query);
return false;
}
$productos = array();
while($fila=$recordSet->FetchRow()) {
$productos[] = new ProductoVO($fila['id_producto'], $fila['id_categoria'], $fila['nombre'],
$fila['descripcion'], $fila['precio'], $fila['stock'], $fila['importancia'],
$fila['imagen']);
}
return $productos;
}
}
?>
Código:
<?php
class ProductoVO {
var $idProducto;
var $idCategoria;
var $nombre;
var $descripcion;
var $precio;
var $stock;
var $importancia;
var $imagen;
function ProductoVO($ip, $ic, $n, $d, $p, $s, $i, $im){
$this->idProducto = $ip;
$this->idCategoria = $ic;
$this->nombre = $n;
$this->descripcion = $d;
$this->precio = $p;
$this->stock = $s;
$this->importancia = $i;
$this->imagen = $im;
}
}
?>
Código:
{section name=i loop=$lista}
<tr>
<td><input type="checkbox" name="seleccion[]" id="seleccion" value="{$lista[i]->idProducto}"></td>
<td>{$lista[i]->idProducto}</td>
<td>{$lista[i]->nombre}</td>
</tr><br/>
{/section}
Y la base de datos es esta:
Código:
CREATE DATABASE IF NOT EXISTS `tienda` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE `tienda`;
CREATE TABLE IF NOT EXISTS `producto` (
`id_producto` int(10) unsigned NOT NULL AUTO_INCREMENT,
`id_categoria` int(10) unsigned NOT NULL,
`nombre` varchar(20) DEFAULT NULL,
`descripcion` varchar(64) DEFAULT NULL,
`precio` decimal(10,0) DEFAULT NULL,
`stock` int(10) unsigned DEFAULT NULL,
`importancia` int(10) unsigned DEFAULT NULL,
`imagen` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id_producto`),
KEY `id_categoria` (`id_categoria`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=60 ;
INSERT INTO `producto` (`id_producto`, `id_categoria`, `nombre`, `descripcion`, `precio`, `stock`, `importancia`, `imagen`) VALUES
(1, 3, 'Osito Hugo', '20 cm. felpa marron corbata azul toko', '50', 20, 2, ''),
(2, 1, 'Arreglo Princesa', 'Rosas y claveles jarron vidrio', '85', 10, 3, 'flor_prince_ch.jpg'),
(3, 1, 'Rosa Roja en caja', '40 cm. Rosa Importada', '26', 2, 2, ''),
(7, 13, 'Aretes Sea Stars', 'Estrella de mar con peces y estrellas plata', '100', 10, 1, ''),
(56, 2, 'Zapatillas Platanito', 'Gamuzadas y Adornos', '479', 150, 2, '');
Pero al cambiar en configure.php para que funcione el smarty3, sale el error.
Agradeceré me ayuden con lo este código.
Gracias.