<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-714113637208876586</id><updated>2025-08-25T08:39:30.732-07:00</updated><category term="PHP"/><category term="ZEND FRAMEWORK"/><category term="COMPUTACION"/><category term="PROGRAMACION"/><title type='text'>Angelorum</title><subtitle type='html'>Por favor, haz un clic sobre los anuncios cuando pases por mi blog, ya? =)</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://angelorum.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://angelorum.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Angelorum</name><uri>http://www.blogger.com/profile/05492306132126056849</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_VvK-zBv166I/SpLtZ6qYDhI/AAAAAAAAAP8/qLgq_yl2NzU/S220/yo+sentado.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-714113637208876586.post-1341995786787817225</id><published>2010-09-14T17:04:00.000-07:00</published><updated>2010-11-20T18:37:20.524-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="ZEND FRAMEWORK"/><title type='text'>Zend Framework  5: El Modelo de datos</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Esta es la quinta parte de &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-1-instalacion.html&quot;&gt;mi tutorial de Zend&lt;/a&gt;. La parte anterior la puedes hallar &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-4-controladores-y.html&quot;&gt;aquí&lt;/a&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Hasta ahora hemos mostrado cómo crear un controlador y sus respectivas acciones, que no son nada más que crear una clase en PHP y agregarle funciones. Pero que esto debe ser hecho usando la línea de comandos (zf.bat ó zf.sh) para que también se agreguen los datos al archivo xml de configuración del proyecto.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ahora lidiaremos con la parte del Modelo, es decir, con el acceso a bases de datos.&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para los siguientes artículos de este tutorial desarrollaremos un pequeño sistema para guardar datos de álbumes de música, artistas y temas. Usaremos una base de datos Mysql. Asumo que tú, esmerado estudiante, posees conocimientos de SQL&amp;nbsp; y sabes cómo crear una base de datos en MySql, crear usuarios y darles privilegios.&lt;/div&gt;&lt;br /&gt;
Recomiendo usar &lt;a href=&quot;http://mysql-gui-tools.malavida.com/&quot;&gt;Mysql GUI Tools&lt;/a&gt;. Es una heramienta que permite administrar bases de datos MySql. Fue creada por MySql, tiene una bonita interfaz gráfica y es gratis.&lt;a href=&quot;http://dev.mysql.com/downloads/gui-tools/&quot;&gt;&amp;nbsp; Descárgala desde aquí.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creando la base de datos&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Este es el script de la base de datos que procederemos a crear:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Sql&quot; name=&quot;code&quot;&gt;-- MySQL Administrator dump 1.4
--
-- ------------------------------------------------------
-- Server version&amp;nbsp;&amp;nbsp;&amp;nbsp; 5.0.45-community-nt


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=&#39;NO_AUTO_VALUE_ON_ZERO&#39; */;


--
-- Create schema albums
--

CREATE DATABASE IF NOT EXISTS albums;
USE albums;

--
-- Definition of table `album`
--

DROP TABLE IF EXISTS `album`;
CREATE TABLE `album` (
&amp;nbsp; `id` int(11) NOT NULL auto_increment,
&amp;nbsp; `artista_id` int(11) default NULL,
&amp;nbsp; `nombre` varchar(50) default NULL,
&amp;nbsp; `fecha` date default NULL,
&amp;nbsp; `descripcion` varchar(100) default NULL,
&amp;nbsp; PRIMARY KEY&amp;nbsp; (`id`),
&amp;nbsp; KEY `fk_relationship_1` (`artista_id`),
&amp;nbsp; CONSTRAINT `fk_relationship_1` FOREIGN KEY (`artista_id`) REFERENCES `artista` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `album`
--

/*!40000 ALTER TABLE `album` DISABLE KEYS */;
INSERT INTO `album` (`id`,`artista_id`,`nombre`,`fecha`,`descripcion`) VALUES 
&amp;nbsp;(1,1,&#39;nos sobran los motivos&#39;,&#39;2000-09-10&#39;,&#39;grabacion en vivo&#39;),
&amp;nbsp;(2,1,&#39;de juez y parte&#39;,&#39;1995-09-10&#39;,&#39;album&#39;),
&amp;nbsp;(3,1,&#39;estaboca es mia&#39;,&#39;1993-09-10&#39;,&#39;album muy bueno&#39;);
/*!40000 ALTER TABLE `album` ENABLE KEYS */;


--
-- Definition of table `artista`
--

DROP TABLE IF EXISTS `artista`;
CREATE TABLE `artista` (
&amp;nbsp; `id` int(11) NOT NULL auto_increment,
&amp;nbsp; `nombre` varchar(50) NOT NULL,
&amp;nbsp; `descripcion` varchar(100) default NULL,
&amp;nbsp; `email` varchar(100) default NULL,
&amp;nbsp; `fecha_ingreso` datetime default NULL,
&amp;nbsp; PRIMARY KEY&amp;nbsp; (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `artista`
--

/*!40000 ALTER TABLE `artista` DISABLE KEYS */;
INSERT INTO `artista` (`id`,`nombre`,`descripcion`,`email`,`fecha_ingreso`) VALUES 
&amp;nbsp;(1,&#39;joaquin sabina&#39;,&#39;trobador español&#39;,&#39;joaquin@sabina.es&#39;,&#39;2010-10-22 00:00:00&#39;),
&amp;nbsp;(2,&#39;bruce dickinson&#39;,&#39;rockero ingles&#39;,&#39;bruce@hell.net&#39;,&#39;2010-10-22 00:00:00&#39;),
&amp;nbsp;(3,&#39;yann tiernsen&#39;,&#39;compositor frances&#39;,&#39;yann@france.net&#39;,&#39;2009-01-01 00:00:00&#39;);
/*!40000 ALTER TABLE `artista` ENABLE KEYS */;


--
-- Definition of table `temas`
--

DROP TABLE IF EXISTS `temas`;
CREATE TABLE `temas` (
&amp;nbsp; `id` int(11) NOT NULL auto_increment,
&amp;nbsp; `album_id` int(11) default NULL,
&amp;nbsp; `titulo` varchar(50) NOT NULL,
&amp;nbsp; `duracion` time default NULL,
&amp;nbsp; PRIMARY KEY&amp;nbsp; (`id`),
&amp;nbsp; KEY `fk_relationship_2` (`album_id`),
&amp;nbsp; CONSTRAINT `fk_relationship_2` FOREIGN KEY (`album_id`) REFERENCES `album` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;

--
-- Dumping data for table `temas`
--

/*!40000 ALTER TABLE `temas` DISABLE KEYS */;
INSERT INTO `temas` (`id`,`album_id`,`titulo`,`duracion`) VALUES 
&amp;nbsp;(1,3,&#39;esta noche contigo&#39;,&#39;00:05:00&#39;),
&amp;nbsp;(2,3,&#39;por el boulevard de los sueños rotos&#39;,&#39;00:07:00&#39;),
&amp;nbsp;(3,3,&#39;más de cien mentiras&#39;,&#39;00:08:00&#39;),
&amp;nbsp;(4,3,&#39;mujeres fatal&#39;,&#39;00:04:00&#39;),
&amp;nbsp;(5,3,&#39;besos con sal&#39;,&#39;00:03:30&#39;);
/*!40000 ALTER TABLE `temas` ENABLE KEYS */;




/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

&lt;/pre&gt;&lt;br /&gt;
Ahora, crearemos un usuario MySQL que tenga privilegios de insert, update, delete y select sobre la base de datos albums (si no sabes cómo hacer esto, puedes usar&amp;nbsp; al usuario root si quieres, aunque no es recomendable hacer eso en un ambiente de desarrollo serio)&lt;br /&gt;
&lt;br /&gt;
Crearemos al usuario albumusuario, clave: 123&lt;br /&gt;
Bien, ya estamos listos para empezar a trabajar con la base de datos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conectando la base de datos con el proyecto en ZF&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Primero, abramos al archivo /application/configs/application.ini y agreguemos lo siguiente (las nuevas líneas están destacadas):&lt;br /&gt;
&lt;br /&gt;
[production]&lt;br /&gt;
phpSettings.display_startup_errors = 0&lt;br /&gt;
phpSettings.display_errors = 0&lt;br /&gt;
includePaths.library = APPLICATION_PATH &quot;/../library&quot;&lt;br /&gt;
bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot;&lt;br /&gt;
bootstrap.class = &quot;Bootstrap&quot;&lt;br /&gt;
appnamespace = &quot;Application&quot;&lt;br /&gt;
resources.frontController.controllerDirectory = APPLICATION_PATH &quot;/controllers&quot;&lt;br /&gt;
resources.frontController.params.displayExceptions = 0&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;resources.db.adapter = PDO_MYSQL&lt;br /&gt;
resources.db.params.host = localhost&lt;br /&gt;
resources.db.params.username = albumusuario&lt;br /&gt;
resources.db.params.password = 123&lt;br /&gt;
resources.db.params.dbname = albums&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
[staging : production]&lt;br /&gt;
&lt;br /&gt;
[testing : production]&lt;br /&gt;
phpSettings.display_startup_errors = 1&lt;br /&gt;
phpSettings.display_errors = 1&lt;br /&gt;
&lt;br /&gt;
[development : production]&lt;br /&gt;
phpSettings.display_startup_errors = 1&lt;br /&gt;
phpSettings.display_errors = 1&lt;br /&gt;
resources.frontController.params.displayExceptions = 1&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Nota: para que esto funcione, php debe tener habilitado el adaptador&amp;nbsp; &lt;b&gt;&lt;b&gt;PDO_MYSQL. &lt;/b&gt;&lt;/b&gt;Debes asegurarte de que sea así. En Xampp viene habilitado por defecto, pero puede que en tu instalación no sea así.&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;Para habilitarlo, debes abrir php.ini y asegurarte de que&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;pre class=&quot;code&quot;&gt;extension=&lt;span class=&quot;search_hit&quot;&gt;pdo_mysql&lt;/span&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;i&gt;esté descomentado, y reiniciar apache.&lt;/i&gt;&lt;/pre&gt;&lt;pre class=&quot;code&quot;&gt;&lt;/pre&gt;&lt;br /&gt;
Para qué hacemos esto en el archivo applicacion.ini? Pues porque al iniciarse ZF, se conectará a la base de datos&amp;nbsp; usando los parámetros de resources.db. ZF creará por sí mismo la cadena de conección, dependiendo del adaptador que estemos usando. Una vez colocadas estas líneas, podemos empezar a hacer consultas a la base de datos sin preocuparnos.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creando las clases del Modelo&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Ahora crearemos las clases PHP&amp;nbsp; que representarán a las tablas de la base de datos. Esto es muy sencillo.&lt;br /&gt;
&lt;br /&gt;
Tipeamos Alt+Z para ejecutar un comando de Zend desde Netbeans, escribimos &#39;tabl&#39; en el filtro y seleccionamos el comando&lt;br /&gt;
&lt;b&gt;create db-table &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
y en Parámeteros escribimos: &lt;b&gt;album album &lt;/b&gt;(nombre_clase nombre_tabla_referenciada)&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDYH-l-nWbxe5K7gCL4xCVsHAY9sxeQiUz87hgBaLsCAFZ9l50sFUqN1zi5pzlL0TlLoN3gijLQEMG-gzCXYtALPg1YXKNM1iFIjDt394yrHWhyphenhyphenhYFS6cwsSz_cCK7UYf8OAKqHF5Ntrg0/s1600/zf_052.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;499&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDYH-l-nWbxe5K7gCL4xCVsHAY9sxeQiUz87hgBaLsCAFZ9l50sFUqN1zi5pzlL0TlLoN3gijLQEMG-gzCXYtALPg1YXKNM1iFIjDt394yrHWhyphenhyphenhYFS6cwsSz_cCK7UYf8OAKqHF5Ntrg0/s640/zf_052.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Observamos que se ha creado una nueva clase en&lt;br /&gt;
/applications/models/DbTable/Album.php :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class Application_Model_DbTable_Album extends Zend_Db_Table_Abstract
{

&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;b&gt;protected $_name = &#39;album&#39;;&lt;/b&gt;
}&lt;/pre&gt;&lt;br /&gt;
Esta clase representa a la tabla album de la base de datos, como lo indica la variable protected $_name.&lt;br /&gt;
&lt;br /&gt;
Hagamos los mismo con las otras dos tablas:&lt;br /&gt;
Alt+z y seleccionamos el comando&lt;br /&gt;
&lt;b&gt;create db-table &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
y en Parámeteros escribimos: &lt;b&gt;artista artista &lt;/b&gt;(nombre_clase nombre_tabla_referenciada)&lt;br /&gt;
&lt;br /&gt;
Alt+z y seleccionamos el comando&lt;br /&gt;
&lt;b&gt;create db-table &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
y en Parámeteros escribimos: &lt;b&gt;temas temas&lt;/b&gt;(nombre_clase nombre_tabla_referenciada)&lt;br /&gt;
&lt;br /&gt;
Ahora deberíamos tener tres clases en la carpeta /applications/models/DbTable :&lt;br /&gt;
Album.php&lt;br /&gt;
Artista.php &lt;br /&gt;
Tema.php&lt;br /&gt;
&lt;br /&gt;
Pero ¿Cómo las usamos? Ahora lo veremos&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Usando las clases del Modelo&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Ahora vamos a agregar algo de código en las clases del Modelo de datos.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Abre  /applications/models/DbTable/Album.php&amp;nbsp; y reemplaza su contenido con&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class Application_Model_DbTable_Album extends Zend_Db_Table_Abstract {

&amp;nbsp;&amp;nbsp;&amp;nbsp; //nombre de la tabla de la db a la que hace referencia
&amp;nbsp;&amp;nbsp;&amp;nbsp; protected $_name = &#39;album&#39;;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * devuelve un arreglo con los datos del album con id=$id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $id id del album
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @return &lt;type&gt; arreblo asociativo
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function get($id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $id = (int) $id;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;fetchRow devuelve fila donde id = $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $row = $this-&amp;gt;fetchRow(&#39;id = &#39; . $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!$row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new Exception(&quot;Could not find row $id&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //formateo fecha a dia-mes-año para que se vea mejor
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $fecha = $row-&amp;gt;fecha;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $fecha = date(&quot;d-m-Y&quot;, strtotime($fecha));
//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; die($fecha);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $row-&amp;gt;fecha = $fecha;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $row-&amp;gt;toArray();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&amp;nbsp; agrega un nuevo album a la base de datos
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $artista_id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $nombre
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $fecha fehca de registro de este album en la base de datos
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $descripcion
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function agregar($artista_id, $nombre, $fecha, $descripcion)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $data = array(&#39;artista_id&#39; =&amp;gt; $artista_id, &#39;nombre&#39; =&amp;gt; $nombre,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;fecha&#39; =&amp;gt; $fecha, &#39;descripcion&#39; =&amp;gt; $descripcion);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;insert inserta nuevo album
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;insert($data);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * modifica los datos del album id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $artista_id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $nombre
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $descripcion
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function cambiar($id, $artista_id, $nombre, $fecha, $descripcion)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $data = array(&#39;artista_id&#39; =&amp;gt; $artista_id, &#39;nombre&#39; =&amp;gt; $nombre,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;fecha&#39; =&amp;gt; $fecha, &#39;descripcion&#39; =&amp;gt; $descripcion);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;update cambia datos de album con id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;update($data, &#39;id = &#39; . (int) $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * borra el album con id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function borrar($id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;delete borrar album donde id=$id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;delete(&#39;id =&#39; . (int) $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function listar()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //devuelve todos los registros de la tabla
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $this-&amp;gt;fetchAll();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}

&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/pre&gt;Examina el código con cuidado. Le he agregado a la clase los métidos para agregar, modificar, listar y eliminar registros. Como puedes ver, no se ocupan instrucciones SQL en ninguna parte.&lt;br /&gt;
&lt;br /&gt;
En forma resumida, para manipular una tabla usamos las siguientes funciones:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;$row = $this-&amp;gt;fetchRow(&#39;id = &#39; . $id);&lt;/b&gt;&lt;br /&gt;
devuelve un objeto con los datos del registro de id = $id&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;$this-&amp;gt;insert($data);&lt;/b&gt;&lt;br /&gt;
inserta un nuevo registro en la tabla. $data es un array asociativo con el formato array( &#39;nombre_campo&#39;=&amp;gt;&#39;valor&#39;, &#39;nombre_campo2&#39;=&amp;gt;&#39;valor2&#39;, ...);&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;$this-&amp;gt;update($data, &#39;id = &#39; . (int) $id);&lt;/b&gt;&lt;br /&gt;
actualiza el registro con el id = $id. $data es un aray asociativo, al igual que al llamar a $this-&amp;gt;insert();&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;$this-&amp;gt;delete(&#39;id =&#39; . (int) $id);&lt;/b&gt;&lt;br /&gt;
borra el registro cuya id = $id.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;return $this-&amp;gt;fetchAll();&lt;/b&gt;&lt;br /&gt;
devuelve todos los registros de la base de datos. Puede recibir un parámetro para indicar filtro, orden o paginación.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
El código para la clase /applications/models/DbTable/Artista.php sería:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class Application_Model_DbTable_Artista extends Zend_Db_Table_Abstract {

&amp;nbsp;&amp;nbsp;&amp;nbsp; protected $_name = &#39;artista&#39;;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * devuelve un arreglo con los datos del artista con id=$id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $id id del artista
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @return &lt;type&gt; arreglo asociativo
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function get($id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $id = (int) $id;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;fetchRow devuelve fila donde id = $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $row = $this-&amp;gt;fetchRow(&#39;id = &#39; . $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!$row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new Exception(&quot;Could not find row $id&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $fecha = $row-&amp;gt;fecha_ingreso;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $fecha = date(&quot;d-m-Y&quot;, strtotime($fecha));
//&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; die($fecha);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $row-&amp;gt;fecha_ingreso = $fecha;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $row-&amp;gt;toArray();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&amp;nbsp; agrega un nuevo artista a la base de datos
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function agregar($nombre,&amp;nbsp; $descripcion, $email, $fecha_ingreso)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $data = array(&#39;nombre&#39; =&amp;gt; $nombre,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;descripcion&#39; =&amp;gt; $descripcion, &#39;email&#39; =&amp;gt; $email,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;fecha_ingreso&#39;=&amp;gt;$fecha_ingreso );
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;insert inserta nuevo artista
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;insert($data);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * modifica los datos del artista id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function cambiar($id,$nombre,&amp;nbsp; $descripcion, $email, $fecha_ingreso)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $data = array(&#39;nombre&#39; =&amp;gt; $nombre,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;descripcion&#39; =&amp;gt; $descripcion, &#39;email&#39; =&amp;gt; $email,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;fecha_ingreso&#39;=&amp;gt;$fecha_ingreso );
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;update cambia datos de artista con id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;update($data, &#39;id = &#39; . (int) $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * borra el artista con id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function borrar($id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;delete borrar artista donde id=$id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;delete(&#39;id =&#39; . (int) $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public function listar()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //devuelve todos los registros de la tabla
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $this-&amp;gt;fetchAll();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

}
&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/pre&gt;&lt;br /&gt;
Y el código para El código para la clase /applications/models/DbTable/Temas.php sería:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class Application_Model_DbTable_Temas extends Zend_Db_Table_Abstract {

&amp;nbsp;&amp;nbsp;&amp;nbsp; protected $_name = &#39;temas&#39;;

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * devuelve un arreglo con los datos del tema con id=$id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $id id del tema
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @return &lt;type&gt; arreglo asociativo
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function get($id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $id = (int) $id;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;fetchRow devuelve fila donde id = $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $row = $this-&amp;gt;fetchRow(&#39;id = &#39; . $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!$row)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw new Exception(&quot;Could not find row $id&quot;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $row-&amp;gt;toArray();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; *&amp;nbsp; agrega un nuevo tema a la base de datos
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function agregar($album_id, $titulo, $duracion)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $data = array(&#39;album_id&#39; =&amp;gt; $album_id,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;titulo&#39; =&amp;gt; $titulo, &#39;duracion&#39; =&amp;gt; $duracion);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;insert inserta nuevo tema
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;insert($data);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * modifica los datos del tema id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function cambiar($id, $album_id, $titulo, $duracion)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $data = array(&#39;album_id&#39; =&amp;gt; $album_id,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &#39;titulo&#39; =&amp;gt; $titulo, &#39;duracion&#39; =&amp;gt; $duracion);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;update cambia datos de tema con id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;update($data, &#39;id = &#39; . (int) $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; /**
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * borra el tema con id= $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; * @param &lt;type&gt; $id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function borrar($id)
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //$this-&amp;gt;delete borrar tema donde id=$id
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;delete(&#39;id =&#39; . (int) $id);
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function listar()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //devuelve todos los registros de la tabla
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return $this-&amp;gt;fetchAll();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

}
&lt;/type&gt;&lt;/type&gt;&lt;/type&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
Bien, nuestras clases del Modelo están listas para usarse.&lt;br /&gt;
Ahora, el soçiguiente paso es trabajar con las acciones y las vistas, y es lo que haremos en el&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-6-creando-las-paginas.html&quot;&gt; siguiente artículo.&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://angelorum.blogspot.com/feeds/1341995786787817225/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/714113637208876586/1341995786787817225?isPopup=true' title='26 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/1341995786787817225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/1341995786787817225'/><link rel='alternate' type='text/html' href='http://angelorum.blogspot.com/2010/09/zend-framework-5-el-modelo-de-datos.html' title='Zend Framework  5: El Modelo de datos'/><author><name>Angelorum</name><uri>http://www.blogger.com/profile/05492306132126056849</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_VvK-zBv166I/SpLtZ6qYDhI/AAAAAAAAAP8/qLgq_yl2NzU/S220/yo+sentado.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDYH-l-nWbxe5K7gCL4xCVsHAY9sxeQiUz87hgBaLsCAFZ9l50sFUqN1zi5pzlL0TlLoN3gijLQEMG-gzCXYtALPg1YXKNM1iFIjDt394yrHWhyphenhyphenhYFS6cwsSz_cCK7UYf8OAKqHF5Ntrg0/s72-c/zf_052.png" height="72" width="72"/><thr:total>26</thr:total></entry><entry><id>tag:blogger.com,1999:blog-714113637208876586.post-5696238969862163222</id><published>2010-09-13T16:02:00.000-07:00</published><updated>2010-10-11T23:13:59.835-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COMPUTACION"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="PROGRAMACION"/><category scheme="http://www.blogger.com/atom/ns#" term="ZEND FRAMEWORK"/><title type='text'>Zend Framework  4: Controladores y acciones</title><content type='html'>Este artículo es parte de &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-1-instalacion.html&quot;&gt;mi tutorial de Zend Framework&lt;/a&gt;, y es la continuación de la &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-3-estructura-del.html&quot;&gt;parte 3&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creando nuevas acciones&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;Ahora, como creamos una nueva accion en nuestro controlador index? Pues simple, se hace con un comando usando el zf.bat. Pero lo podemos hacer desde el mismo IDE. &lt;br /&gt;
Primero, le vamos a asignar a los comandos de ZF un hotkey para poder ejecutarlos más rápido. &lt;br /&gt;
Vamos en el menú a Herramientas/Opciones a la pestaña Keymap (o mapeo de teclas o como aparezcan en español), y teclea en Buscar &#39;zend&#39; (sin las comillas)&lt;br /&gt;
&amp;nbsp;Clic en la segunda columna, presiona la tecla Alt y la tecla z (Alt+Z) y Enter. Guarda los cambios. &lt;br /&gt;
&lt;br /&gt;
Ahora, si presionamos Alt+z en la ventana principal del IDE, aparecerá &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjiubwteGXP_6GPbCrUze5k6Dr-DSl2kszFvkI_pMJLQEWgWvPf8I4umnXsRdlPg7HUQSgIxxgyhJfiOu7-ap_L8Fb4FFGDshOsdLyjOCnhEAFq_ImDWz4ZvYkuAz1WsfEoMAHweMJ4lkG/s1600/zf_009.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;499&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjiubwteGXP_6GPbCrUze5k6Dr-DSl2kszFvkI_pMJLQEWgWvPf8I4umnXsRdlPg7HUQSgIxxgyhJfiOu7-ap_L8Fb4FFGDshOsdLyjOCnhEAFq_ImDWz4ZvYkuAz1WsfEoMAHweMJ4lkG/s640/zf_009.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
ese es el listado de todos los comandos de zend.bat disponibles. Para usarlos, hacemos clic en uno de ellos, colocamos en Parámetros los datos requeridos y presionamos el botón Run (ejecutar) o enter.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Para crear una nueva acción&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Crearemos una nueva acción en mi controlador index.&lt;br /&gt;
Presionemos Alt+z para ejecutar un comando de ZF. Cuando se abra la ventana, en filtro escribamos &#39;act&#39; sin comillas, seleccionamos el comando &lt;b&gt;create action&lt;/b&gt; y escribimos &lt;br /&gt;
&#39;&lt;b&gt;prueba index&lt;/b&gt;&#39; y presionamos enter. (esto llama al comando zf create action prueba index)&lt;br /&gt;
&lt;br /&gt;
como se ve en la imagen:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYX9wkTzMhTxtnN7rghH_sfIZhplAZe7QKJDQpEtoBo6efBpp8lxFI1zLEdc6NoQlyV-dGSUqW8DRjm3aO2JkuWlcB5B7x8mZm2j5TzelKzWkKOwFIBywN2XJ5bb6pWdoeraV20xguBSaR/s1600/zf_010.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;499&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYX9wkTzMhTxtnN7rghH_sfIZhplAZe7QKJDQpEtoBo6efBpp8lxFI1zLEdc6NoQlyV-dGSUqW8DRjm3aO2JkuWlcB5B7x8mZm2j5TzelKzWkKOwFIBywN2XJ5bb6pWdoeraV20xguBSaR/s640/zf_010.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Si vemos nuestro archivo &lt;br /&gt;
/application/controllers/IndexController.php&lt;br /&gt;
&lt;br /&gt;
veremos que ahora contiene&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class IndexController extends Zend_Controller_Action
{

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function init()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Initialize action controller here */
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function indexAction()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // action body
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function pruebaAction()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // action body
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;&lt;br /&gt;
Y también veremos que se ha creado un archivo llamado prueba.phtml en&lt;br /&gt;
/application/views/scripts/index/prueba.phtml&lt;br /&gt;
&lt;br /&gt;
Nota: como podemos ver, las paginas .phtml se guardan en &lt;br /&gt;
&lt;b&gt;/application/views/scripts/nombre_controlador/nombre_accion.phtml&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Abramos el archivo &lt;br /&gt;
/application/views/scripts/index/prueba.phtml&lt;br /&gt;
&lt;br /&gt;
borra su contenido y escribe&lt;br /&gt;
&lt;br /&gt;
&amp;lt;h1&amp;gt;Estoy en la vista de la accion prueba()&amp;lt;/h1&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ahora, abriremos esa página por el navegador&lt;br /&gt;
recordemos que la forma de abrirla es&lt;br /&gt;
&lt;br /&gt;
http://localhost/miproyecto/public/nombrecontrolador/nombreaccion&lt;br /&gt;
&lt;br /&gt;
en este caso, seria&lt;br /&gt;
http://localhost/miproyecto/public/index/prueba&lt;br /&gt;
&lt;br /&gt;
veamos cómo quedó:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCJTxnweDG8ej_LZu6u7wcqH9vsj-dhwD4DK3qzY0odJtzTxL3lkCtZZewp3MnrEZG8lN1URzCoySqbN_wuSwmLR1V4WDydXWbzyWfIZ5CHYzkcOL4vNW780AGG66D63H_FU393GX4W2UG/s1600/zf_011.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;282&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiCJTxnweDG8ej_LZu6u7wcqH9vsj-dhwD4DK3qzY0odJtzTxL3lkCtZZewp3MnrEZG8lN1URzCoySqbN_wuSwmLR1V4WDydXWbzyWfIZ5CHYzkcOL4vNW780AGG66D63H_FU393GX4W2UG/s400/zf_011.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;ahora, cómo agregamos un nuevo controlador?&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
Agregando un nuevo controlador&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Presionemos Alt+z para ejecutar un comando de ZF. Cuando se abra la ventana, en filtro escribamos &#39;cont&#39; sin comillas, seleecionamos el comando create controller y escribamos &lt;br /&gt;
&#39;&lt;b&gt;micontrolador&lt;/b&gt;&#39; y presionamos enter. (esto llama al comando zf create controller micontrolador)&lt;br /&gt;
&lt;br /&gt;
como se ve en la imagen:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAHnW4jl_z2TUKJSoHvOneq-vF5BtA7whEvf-iUYekf0dhZ6sh8rqE94PqDA3rcDxF3NFGyyTHwWExVrNNNzEjeYMal_knZrz852WcuwnIPn34uSZwH-kJq9q5CzBybp7N7p0qEutZjiMM/s1600/zf_012.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;500&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAHnW4jl_z2TUKJSoHvOneq-vF5BtA7whEvf-iUYekf0dhZ6sh8rqE94PqDA3rcDxF3NFGyyTHwWExVrNNNzEjeYMal_knZrz852WcuwnIPn34uSZwH-kJq9q5CzBybp7N7p0qEutZjiMM/s640/zf_012.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Ahora, su revisamos la carpeta de los controladores, &lt;br /&gt;
/application/controllers/&lt;br /&gt;
veremos que se ha agregado el archivo MicontroladorController.php con la acción index():&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class MicontroladorController extends Zend_Controller_Action
{

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function init()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Initialize action controller here */
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function indexAction()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // action body
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;&lt;br /&gt;
Y si vamos a donde se guardan los archivos .phtml, veremos que se ha agregado una nueva carpeta con el nombre del controlador, y un nuevo archivo en &lt;br /&gt;
/application/views/scripts/micontrolador/index.phtml&lt;br /&gt;
&lt;br /&gt;
Ahora, apuntemos el navegador a nuesto nuevo controlador:&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/micontrolador&quot;&gt;http://localhost/miproyecto/public/micontrolador&lt;/a&gt;&lt;br /&gt;
ó&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/micontrolador/index&quot;&gt;http://localhost/miproyecto/public/micontrolador/index&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
veremos esto:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_552Gc7nTjkJYDuYCtpli0DJsxYuNo0wVXB3CGC56s52c7-NrqT7lCT0GrtQJc9MAkj1iAH_71cLQfThFSmDeauhrToE3d31rngpgh2vARsEQ8d2RooV8_3dVW6SS_ZX-i0ortmtWtcxK/s1600/zf_013.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;183&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_552Gc7nTjkJYDuYCtpli0DJsxYuNo0wVXB3CGC56s52c7-NrqT7lCT0GrtQJc9MAkj1iAH_71cLQfThFSmDeauhrToE3d31rngpgh2vARsEQ8d2RooV8_3dVW6SS_ZX-i0ortmtWtcxK/s400/zf_013.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Ahora mostraremos como pasar datos desde la accion a la vista, es decir, desde la funcion index() de Micontrolador al archivo /application/views/scripts/micontrolador/index.phtml:&lt;br /&gt;
&lt;br /&gt;
Vamos al archivo&amp;nbsp; MicontroladorController.php y modificaremos algunas cosas:&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class MicontroladorController extends Zend_Controller_Action
{

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function init()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //creamos un objeto vista, para pasarle los datos
&amp;nbsp;&amp;nbsp;&amp;nbsp; //al archivo .phtml en cada accion 
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; $this-&amp;gt;initView();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;view-&amp;gt;baseUrl = $this-&amp;gt;_request-&amp;gt;getBaseUrl();
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function indexAction()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //creo una variable llamada saludo en el objeto vista
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //y le asigno un string
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $this-&amp;gt;view-&amp;gt;saludo = &quot;hola a todos!!&quot;;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;&lt;br /&gt;
Ahora, haremos unas modificaciones en la vista, es decir, el archivo index.phtml. Podemos buscar el archivo entre las carpetas del proyecto, o hacer clic dentro de la funcion indexAction(), boton derecho, Go to View (ir a la Vista)&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimWIiDvtc5qXprRj5-EqA-CJOZTbu1MmBgKQctakrWCuHHkLYt4jBHgLJoZIaKKyvvcQ6zGKTzcGRIZQVSa0UnscoMBujQ_10znGLC6AiLPx0XEPNc_ZaBKl_w8F0LPrn1WHdWqhYd-CRF/s1600/zf_014.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;458&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimWIiDvtc5qXprRj5-EqA-CJOZTbu1MmBgKQctakrWCuHHkLYt4jBHgLJoZIaKKyvvcQ6zGKTzcGRIZQVSa0UnscoMBujQ_10znGLC6AiLPx0XEPNc_ZaBKl_w8F0LPrn1WHdWqhYd-CRF/s640/zf_014.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
esto me traslada inmediatamente a la vista asociada a la accion , en este caso, el archivo /application/views/scripts/micontrolador/index.phtml&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Nota: si desde index.phtml haces boton derecho Navigate/Go to Action, te llevará a la acción&amp;nbsp; asociada a la Vista.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Reemplazaremos su contenido por:&lt;br /&gt;
&amp;lt;p&amp;gt;Vista index de la accion index() de controlador Mi controlador&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;Saludo : &amp;lt;strong&amp;gt;&amp;lt;?php echo $this-&amp;gt;saludo; ?&amp;gt;&amp;lt;/strong&amp;gt;&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ahora, apuntemos el navegador nuevamente al controlador:&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/micontrolador&quot;&gt;http://localhost/miproyecto/public/micontrolador&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGhHsD1DBQeGrtO3NJoP8N6aNQEwVfCa81orjTP6HywvkGZFgNxn3UqBIMMC9wPtnJr5qNCOrgTg_qST_Ch4U90HnsXpfzHdpBPREDtDpDzCrwdO5u6hexn1GKHWkOX0fAX0Cq4VmxmjMP/s1600/zf_015.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgGhHsD1DBQeGrtO3NJoP8N6aNQEwVfCa81orjTP6HywvkGZFgNxn3UqBIMMC9wPtnJr5qNCOrgTg_qST_Ch4U90HnsXpfzHdpBPREDtDpDzCrwdO5u6hexn1GKHWkOX0fAX0Cq4VmxmjMP/s400/zf_015.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
Como podemos ver, la variable &lt;br /&gt;
&lt;b&gt;$this-&amp;gt;view-&amp;gt;saludo = &quot;hola a todos!!&quot;;&lt;/b&gt;&lt;br /&gt;
que asignamos en la accion se muestra en la vista haciendo&lt;br /&gt;
&lt;b&gt;saludo; ?&amp;gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Así, cualquier cosa que asignemos a &lt;b&gt;$this-&amp;gt;view&lt;/b&gt; en la acción puede ser mostrada en la vista.&lt;br /&gt;
&lt;br /&gt;
Te aconsejo practicar creando algunos controladores y acciones y pasando datos desde la acción a la vista usando &lt;b&gt;$this-&amp;gt;view&lt;/b&gt;, para que vayas soltando la mano.&lt;br /&gt;
&lt;br /&gt;
Zend Framework ofrece muchas otras herramientas para facilitar el desarrollo del sistema. Entre ellas están el manejo sesiones, de privilegios de usuario, de parámetros, y la que veremos en la siguiente parte de este tutorial, el acceso a bases de datos: el Modelo.&lt;br /&gt;
&lt;br /&gt;
Pasemos al &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-5-el-modelo-de-datos.html&quot;&gt;siguiente artículo de este tutorial&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://angelorum.blogspot.com/feeds/5696238969862163222/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/714113637208876586/5696238969862163222?isPopup=true' title='15 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/5696238969862163222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/5696238969862163222'/><link rel='alternate' type='text/html' href='http://angelorum.blogspot.com/2010/09/zend-framework-4-controladores-y.html' title='Zend Framework  4: Controladores y acciones'/><author><name>Angelorum</name><uri>http://www.blogger.com/profile/05492306132126056849</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_VvK-zBv166I/SpLtZ6qYDhI/AAAAAAAAAP8/qLgq_yl2NzU/S220/yo+sentado.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjiubwteGXP_6GPbCrUze5k6Dr-DSl2kszFvkI_pMJLQEWgWvPf8I4umnXsRdlPg7HUQSgIxxgyhJfiOu7-ap_L8Fb4FFGDshOsdLyjOCnhEAFq_ImDWz4ZvYkuAz1WsfEoMAHweMJ4lkG/s72-c/zf_009.png" height="72" width="72"/><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-714113637208876586.post-3281267238489326563</id><published>2010-09-13T15:15:00.001-07:00</published><updated>2012-02-20T12:32:33.880-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COMPUTACION"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="PROGRAMACION"/><category scheme="http://www.blogger.com/atom/ns#" term="ZEND FRAMEWORK"/><title type='text'>Zend Framework  3: Estructura del proyecto</title><content type='html'>Este artículo es la tercera parte de &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-1-instalacion.html&quot;&gt;mi&amp;nbsp; tutorial de Zend Framework&lt;/a&gt;. La segunda parte &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-2-vista-general.html&quot;&gt;está acá&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
La estructura del proyecto recién creado se ve así:&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzKeuku1-AW5KtI1yaDJwhJ9DX9210ENUjOJU3UgwfZTIGKxtnrfDLOvpkI_jaBowYdQXP52Z7CukhEeSLjCA3xQyBIlTXqL1w1ijmLIOSTLNKOxRt5HmOJznYWCYzVvGEXNODAOsMFzFA/s1600/zf_005.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzKeuku1-AW5KtI1yaDJwhJ9DX9210ENUjOJU3UgwfZTIGKxtnrfDLOvpkI_jaBowYdQXP52Z7CukhEeSLjCA3xQyBIlTXqL1w1ijmLIOSTLNKOxRt5HmOJznYWCYzVvGEXNODAOsMFzFA/s640/zf_005.png&quot; width=&quot;387&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Un poco confuso ¿no? Mas no colapses aún, intrépido programador, que es sencillo de entender.&lt;br /&gt;
Antes de seguir, asegurémonos de que nuestro servidor web está configurado para&amp;nbsp; usar ZF.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Configuración de Apache (mod_rewrite)&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para que ZF funcione, todas las urls deben ser procesadas por el archivo index.php, el cual decidirá qué hacer con ellas. Por ejemplo, si yo escribo&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/&quot;&gt;&lt;u&gt;http://localhost/miproyecto/public/&lt;/u&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/algo/otro&quot;&gt;&lt;u&gt;http://localhost/miproyecto/public/algo/otro&lt;/u&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/saludo/hola&quot;&gt;&lt;u&gt;http://localhost/miproyecto/public/saludo/hola&lt;/u&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
todas esas páginas deberían redirigirse a &lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/index.php&quot;&gt;http://localhost/miproyecto/public&lt;b&gt;/index.php&lt;/b&gt;&lt;/a&gt; , el cual decidirá qué paginas mostrar, según la url que se le envíe.&lt;br /&gt;
&lt;br /&gt;
Para que esto se pueda hacer, en el archivo de configuración de apache,&lt;b&gt; httpd.conf :&lt;/b&gt;&lt;br /&gt;
G:\xampp\xampp\apache\conf\httpd.conf&lt;br /&gt;
&lt;br /&gt;
Debemos descomentar esto:&lt;br /&gt;
&lt;b&gt;LoadModule rewrite_module modules/mod_rewrite.so&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
y reiniciar apache.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&amp;nbsp;Ahora, probaremos nuestro proyecto recién creado en el artículo anterior. &lt;b&gt;Debemos inciar Apache ( si estamos usando Xampp, podemos hacerlo desde el Xampp Control Panel)&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Una vez que estamos seguros de que mod_rewrite está activado, abramos nuestro navegador favorito y escribamos la direccion:&lt;span id=&quot;goog_2118607752&quot;&gt;&lt;/span&gt;&lt;span id=&quot;goog_2118607753&quot;&gt;&lt;/span&gt;&lt;a href=&quot;http://www.blogger.com/&quot;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/&quot;&gt;http://localhost/miproyecto/public/&lt;/a&gt;&lt;span id=&quot;goog_2118607750&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
y veremos esto:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhevY_75nlbQenCcEhzNO-XfdLGfJfm2ujyRfs-ODlIMr3jyJcsSncgv21OfRm3OTi6_bXjGmhBAKoBJ72IlfX8qfGdiyW69GMjBy-_VQCM74i7a5_sUIIttM5-X8tTQkzCDGg-phsHL_dS/s1600/zf_006.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;270&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhevY_75nlbQenCcEhzNO-XfdLGfJfm2ujyRfs-ODlIMr3jyJcsSncgv21OfRm3OTi6_bXjGmhBAKoBJ72IlfX8qfGdiyW69GMjBy-_VQCM74i7a5_sUIIttM5-X8tTQkzCDGg-phsHL_dS/s400/zf_006.png&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
¡ Felicidades!. Nuestro proyecto en ZF está creado con éxito. &lt;br /&gt;
&lt;br /&gt;
Ahora echaremos un vistazo en los archivos, carpetas y el resto de la estructura de ZF.&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Como habíamos dicho, esta es la estructura de carpetas del proyecto:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzKeuku1-AW5KtI1yaDJwhJ9DX9210ENUjOJU3UgwfZTIGKxtnrfDLOvpkI_jaBowYdQXP52Z7CukhEeSLjCA3xQyBIlTXqL1w1ijmLIOSTLNKOxRt5HmOJznYWCYzVvGEXNODAOsMFzFA/s1600/zf_005.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;640&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzKeuku1-AW5KtI1yaDJwhJ9DX9210ENUjOJU3UgwfZTIGKxtnrfDLOvpkI_jaBowYdQXP52Z7CukhEeSLjCA3xQyBIlTXqL1w1ijmLIOSTLNKOxRt5HmOJznYWCYzVvGEXNODAOsMFzFA/s640/zf_005.png&quot; width=&quot;388&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&amp;nbsp;Veamos el archivo index.php, ubicado en la carpeta public&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;// Define path to application directory
defined(&#39;APPLICATION_PATH&#39;)
    || define(&#39;APPLICATION_PATH&#39;, realpath(dirname(__FILE__) . &#39;/../application&#39;));

// Define application environment
defined(&#39;APPLICATION_ENV&#39;)
    || define(&#39;APPLICATION_ENV&#39;, (getenv(&#39;APPLICATION_ENV&#39;) ? getenv(&#39;APPLICATION_ENV&#39;) : &#39;production&#39;));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . &#39;/../library&#39;),
    get_include_path(),
)));

/** Zend_Application */
require_once &#39;Zend/Application.php&#39;;

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . &#39;/configs/application.ini&#39;
);
$application-&amp;gt;bootstrap()
            -&amp;gt;run();
&lt;/pre&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
Lo explicaremos por partes:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;// Define path to application directory
defined(&#39;APPLICATION_PATH&#39;)
&amp;nbsp;&amp;nbsp;&amp;nbsp; || define(&#39;APPLICATION_PATH&#39;, realpath(dirname(__FILE__) . &#39;/../application&#39;));
&lt;/pre&gt;indica que la carpeta en donde estarán las clases PHP que implementan el modelo MVC estarán dentro de la carpeta /../application&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;// Define application environment
defined(&#39;APPLICATION_ENV&#39;)
&amp;nbsp;&amp;nbsp;&amp;nbsp; || define(&#39;APPLICATION_ENV&#39;, (getenv(&#39;APPLICATION_ENV&#39;) ?&amp;nbsp;&lt;/pre&gt;&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;getenv(&#39;APPLICATION_ENV&#39;) : &#39;production&#39;));
&lt;/pre&gt;indica que nuestro sistema al funcionar ocupará la configuración guardada en la sección &#39;production&#39;. Como veremos muy pronto, hay otras secciones más como &#39;development&#39; y &#39;testing&#39; que pueden tener otros valores. Por ejemplo, el indicar si se deben mostrar o no los mensajes de error.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
&amp;nbsp;&amp;nbsp;&amp;nbsp; realpath(APPLICATION_PATH . &#39;/../library&#39;),
&amp;nbsp;&amp;nbsp;&amp;nbsp; get_include_path(),
&lt;/pre&gt;Indica que nuestras clases y librerías de php que coloquemos en la carpeta /../library serán incluidas en el include_path del sistema.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;/** Zend_Application */
require_once &#39;Zend/Application.php&#39;;

// Create application, bootstrap, and run
$application = new Zend_Application(
&amp;nbsp;&amp;nbsp;&amp;nbsp; APPLICATION_ENV,
&amp;nbsp;&amp;nbsp;&amp;nbsp; APPLICATION_PATH . &#39;/configs/application.ini&#39;
);
$application-&amp;gt;bootstrap()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -&amp;gt;run();
&lt;/pre&gt;&lt;br /&gt;
crea un objeto&amp;nbsp; Zend_Application según la configuración indicada en el archivo &#39;/configs/application.ini&#39; y lo echa a correr. Este objeto es el que hace la redireccion de las urls, inicializa las demás clases, las carga, etc.&lt;br /&gt;
&lt;br /&gt;
Ahora examinemos el archivo /configs/application.ini :&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH &quot;/../library&quot;
bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot;
bootstrap.class = &quot;Bootstrap&quot;
appnamespace = &quot;Application&quot;
resources.frontController.controllerDirectory = APPLICATION_PATH &quot;/controllers&quot;
resources.frontController.params.displayExceptions = 0

[staging : production]

[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1

[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1 
&lt;/pre&gt;&lt;br /&gt;
Este archivo permite indicar el valor de algunas variables de entorno del sistema. Como el objeto&amp;nbsp; Zend_Application lee este archivo al iniciarse, podemos modificar algunos valores en este archivo y así ahorrarnos el tocar el código en PHP.&lt;br /&gt;
&lt;br /&gt;
En este archivo tenemos tres secciones (aunque nosotros podriamos agregar más):&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;[production]&lt;/li&gt;
&lt;li&gt;[staging : production] (que hereda todas las variables desde production, y los agrega o modifica)&lt;/li&gt;
&lt;li&gt;[testing : production] (que hereda todas las variables desde production, y los agrega o modifica)&lt;/li&gt;
&lt;li&gt;[development : production] (que hereda todas las variables desde production, y los agrega o modifica)&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
Por ejemplo, como development hereda las variables de la sección de producción, esta contendría:&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;phpSettings.display_startup_errors&lt;/b&gt; = &lt;b&gt;1&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;phpSettings.display_errors&lt;/b&gt; = &lt;b&gt;1&lt;/b&gt;&lt;br /&gt;
includePaths.library = APPLICATION_PATH &quot;/../library&quot;&lt;br /&gt;
bootstrap.path = APPLICATION_PATH &quot;/Bootstrap.php&quot;&lt;br /&gt;
bootstrap.class = &quot;Bootstrap&quot;&lt;br /&gt;
appnamespace = &quot;Application&quot;&lt;br /&gt;
resources.frontController.controllerDirectory = APPLICATION_PATH &quot;/controllers&quot;&lt;br /&gt;
&lt;b&gt;resources.frontController.params.displayExceptions&lt;/b&gt; = &lt;b&gt;1&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Pero a la vez modifica el valor de las variables&lt;br /&gt;
phpSettings.display_startup_errors,&lt;br /&gt;
phpSettings.display_errors,&lt;br /&gt;
resources.frontController.params.displayExceptions&lt;br /&gt;
&lt;br /&gt;
para que muestren los errores. ¿Qué significa esto? Que si estamos corriendo el sistema en ambiente de production no veremos errores de codigo o de coneccion&amp;nbsp; en la pantalla, pero si lo corremos en ambiente de development, veremos el trazado de errores indicando el nombre de la clase en que ocurrió el error, el código que falló, etc.&lt;br /&gt;
&lt;br /&gt;
Ahora, cómo le decimos al sistema en qué ambiente debe funcionar, produciotn, testing o development? Simple, volvamos al archivo index.php en la carpeta public a las líneas 8 y 9:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;// Define application environment
defined(&#39;APPLICATION_ENV&#39;)
    || define(&#39;APPLICATION_ENV&#39;, (getenv(&#39;APPLICATION_ENV&#39;) ?&lt;/pre&gt;&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;getenv(&#39;APPLICATION_ENV&#39;) : &#39;production&#39;));
&lt;/pre&gt;&lt;br /&gt;
si cambiáramos production por development, entonces nuestro sistema mostraría los errores y funcionaría con la configuración de development. Esto hace más fácil el desarrollo, pues podemos tener distintas configuraciones para distintos ambientes en una forma sencilla.&lt;br /&gt;
&lt;br /&gt;
También en el archivo&amp;nbsp; application.ini podemos indicar los parámetros de la o las bases de datos a las que deseamos acceder, entre muchas otras cosas. Más de esto después.&lt;br /&gt;
&lt;br /&gt;
Ahora sigamos viendo los demás archivos.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;application/Boostrap.php&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Este archivo nos sirve para inicializar las clases del modelo MVC y llamar a algunas funciones que queremos que se llamen para todas ellas&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{


}
&lt;/pre&gt;&lt;br /&gt;
Como pueden ver no viene con nada, pero nosotros podríamos agregarle un código&amp;nbsp; como este:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;protected function _initView() 
{ 
  $view = new Zend_View(); 
  $view-&amp;gt;setEncoding(&#39;UTF-8&#39;); 
  $view-&amp;gt;doctype(&#39;XHTML1_STRICT&#39;); 
  $view-&amp;gt;headMeta()-&amp;gt;appendHttpEquiv( 
                       &#39;Content-Type&#39;, &#39;text/html;charset=utf-8&#39; 
  ); 
  $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper( 
                 &#39;ViewRenderer&#39; 
  ); 
  $viewRenderer-&amp;gt;setView($view); 
  return $view; 
} 
&lt;/pre&gt;El cual, dicho en forma simple, indica que todas las paginas creadas en este proyecto serán de codificación&amp;nbsp; XHTML1_STRICT, con conjunto de caracteres&amp;nbsp; utf-8.&lt;br /&gt;
&lt;br /&gt;
Existen muchas otras clases y métodos que se pueden configurar en este archivo, pero como este es un tutorial sencillo, no daremos más ejemplos.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Manejo de Controladores y Vistas&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Como dijimos al principio, ZF implementa el modelo MVC, donde las clases del Modelo son las que acceden a las tablas de las bases de datos, las de la Vista son las páginas con HTML y las del Controlador son las que controlan (valga la redundancia) a las dos anteriores.&lt;br /&gt;
&lt;br /&gt;
Dentro de ZF, &lt;b&gt;un Controlador es una Clase&lt;/b&gt; y &lt;b&gt;las vistas son creadas por métodos de esta clase, llamados Acciones&lt;/b&gt;.&lt;br /&gt;
La url indica el controlador y la acción a la que se llama. Por ejemplo, si colocamos en el navegador:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/album/agregar&quot;&gt;http://localhost/miproyecto/public/album/agregar&lt;/a&gt;&lt;br /&gt;
entonces en nuestro proyecto deberemos tener una &lt;b&gt;clase controlador llamada Album&lt;/b&gt;, que tenga un &lt;b&gt;método llamado agregar&lt;/b&gt;, que cree una página web llamada agregar.phtml&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/album/index&quot;&gt;http://localhost/miproyecto/public/album/index&lt;/a&gt;&lt;br /&gt;
entonces en nuestro proyecto deberemos tener una &lt;b&gt;clase controlador&amp;nbsp; llamada Album&lt;/b&gt;, que tenga un &lt;b&gt;método llamado index&lt;/b&gt;, que cree una página web llamada index.phtml&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/album/borrar&quot;&gt;http://localhost/miproyecto/public/album/borrar&lt;/a&gt;&lt;br /&gt;
entonces en nuestro proyecto deberemos tener una c&lt;b&gt;lase controlador&amp;nbsp; llamada Album&lt;/b&gt;, que tenga un &lt;b&gt;método llamado borrar&lt;/b&gt;, que cree una página web llamada borrar.phtml&lt;br /&gt;
&lt;br /&gt;
Aquí se muestra el código de la clase mencionada:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class AlbumController extends Zend_Controller_Action
{

&amp;nbsp;&amp;nbsp;&amp;nbsp; public function init()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* Initialize action controller here */
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; //accion agregar
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function agregarAction()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // desde aquí coloco datos al archivo 
&amp;nbsp;&amp;nbsp;&amp;nbsp; // agregar.phtml, que es el que se mostrará al final
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&amp;nbsp;&amp;nbsp;&amp;nbsp; //accion index
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function indexAction()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // desde aquí coloco datos al archivo 
&amp;nbsp;&amp;nbsp;&amp;nbsp; // index.phtml, que es el que se mostrará al final
&amp;nbsp;&amp;nbsp;&amp;nbsp; }

&amp;nbsp;&amp;nbsp;&amp;nbsp; //accion borrar
&amp;nbsp;&amp;nbsp;&amp;nbsp; public function borrarAction()
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // desde aquí coloco datos al archivo 
&amp;nbsp;&amp;nbsp;&amp;nbsp; // borrar.phtml, que es el que se mostrará al final
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
}
&lt;/pre&gt;&lt;br /&gt;
Al crear un proyecto en ZF se crea automáticamente un controlador llamado Index, con la accion llamada index, que son las que se llaman por defecto, si es que o se indica nombre de controlador ni accion:&lt;br /&gt;
Por eso, cuando hacemos&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public&quot;&gt;http://localhost/miproyecto/public&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/index&quot;&gt;http://localhost/miproyecto/public/index&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/index/index&quot;&gt;http://localhost/miproyecto/public/index/index&lt;/a&gt;&lt;br /&gt;
llamamos al controlador index, accion index()&lt;br /&gt;
&lt;br /&gt;
Dónde está la clase controladora index? Podemos verla en &lt;br /&gt;
/application/controllers/IndexController.php&lt;br /&gt;
&lt;br /&gt;
Tocas las clases controladoras tienen el nombre de la forma NombreclaseController.php&lt;br /&gt;
Si abrimos la clase /application/controllers/IndexController.php, veremos que dentro contiene la función indexAction(), que es la que se llama cuando hacemos &lt;br /&gt;
&lt;a href=&quot;http://localhost/miproyecto/public/index/index&quot;&gt;http://localhost/miproyecto/public/index/index&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
o alguna de las de más arriba&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;Php&quot; name=&quot;code&quot;&gt;class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
    }
}
&lt;/pre&gt;&lt;br /&gt;
Ahora, cómo creamos una nueva acción y nuevas clases controladoras? &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-4-controladores-y.html&quot;&gt;Lee el siguiente artículo&lt;/a&gt;.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://angelorum.blogspot.com/feeds/3281267238489326563/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/714113637208876586/3281267238489326563?isPopup=true' title='12 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/3281267238489326563'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/3281267238489326563'/><link rel='alternate' type='text/html' href='http://angelorum.blogspot.com/2010/09/zend-framework-3-estructura-del.html' title='Zend Framework  3: Estructura del proyecto'/><author><name>Angelorum</name><uri>http://www.blogger.com/profile/05492306132126056849</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_VvK-zBv166I/SpLtZ6qYDhI/AAAAAAAAAP8/qLgq_yl2NzU/S220/yo+sentado.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzKeuku1-AW5KtI1yaDJwhJ9DX9210ENUjOJU3UgwfZTIGKxtnrfDLOvpkI_jaBowYdQXP52Z7CukhEeSLjCA3xQyBIlTXqL1w1ijmLIOSTLNKOxRt5HmOJznYWCYzVvGEXNODAOsMFzFA/s72-c/zf_005.png" height="72" width="72"/><thr:total>12</thr:total></entry><entry><id>tag:blogger.com,1999:blog-714113637208876586.post-3384335667375980490</id><published>2010-09-13T15:12:00.001-07:00</published><updated>2012-02-20T12:31:17.265-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COMPUTACION"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="ZEND FRAMEWORK"/><title type='text'>Zend Framework 2: Crear un proyecto usando Netbeans</title><content type='html'>&lt;i&gt;Este artículo es la segunda parte de mi tutorial de &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-1-instalacion.html&quot;&gt;Zend Framework 1: Introducción&lt;/a&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Breve explicación de qué hace Zend Framework&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
ZF es , como ya dije, un conjunto de librerías que nos permiten crear sistemas con PHP usando&amp;nbsp; la &lt;a href=&quot;http://es.wikipedia.org/wiki/Modelo_Vista_Controlador&quot;&gt;metodología MVC&lt;/a&gt; (Modelo, Vista, Controlador). Pero para que ZF funcione, nuestro sistema web debe estar organizado en una forma especial,. Se deben crear carpetas con nombres específicos, y debemos guardar los archivos PHP que forman la Vista del sistema en cierta carpeta, y los archivos que forman el Modelo en otra carpeta, etc.&amp;nbsp; Además se debe crear un archivo llamado &lt;b&gt;.zfproject.xml&lt;/b&gt; en donde se indica un detalle de las clases PHP usadas, qué rol juegan y dónde se ubican.&lt;br /&gt;
&lt;br /&gt;
Menudo lío, ¿verdad? Pero no te desesperes, ya que ZF viene con un intérprete de línea de comandos que hace todo esto por nosotros: &lt;b&gt;zf.bat&lt;/b&gt; (ó zf.sh para Linux). Usando este comando podemos crear projectos de ZF que nos crearán toda la estructura de carpetas y el archivo .zfproject.xml con los detalles del proyecto. También lo usaremos para crear el esqueleto de las clases que implementan el modelo MVC, como veremos más adelante.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&amp;nbsp;Instalando nuestro ambiente de Trabajo&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Antres de empezar a codificar, lo mejor sería hacernos con un buen IDE para trabajar en PHP. Puedes usar el que más te guste, yo usaré &lt;a href=&quot;http://netbeans.org/&quot;&gt;NetBeans 6.9.1&lt;/a&gt; (la version 7.x tambien trae soporte, desde luego). Originalmente este fue pensado como un IDE para trabajar en java, pero tiene extensiones para trabajar en PHP, C/C++ y otros lenguajes. Además, podemos configurarlo para que podamos ejecutar el comando zf.bat directamente desde el IDE (opcional). Netbeans es gratuito, fácil de usar y multilenguaje. Puedes bajarlo &lt;a href=&quot;http://netbeans.org/downloads/index.html&quot;&gt;desde acá&lt;/a&gt;. Si solo lo vas a usar para codificar en PHP, puedes bajarte la versión&amp;nbsp; para PHP, que es más liviana que la que trae soporte para todos los lenguajes.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
Instalar Netbeans es fácil. Solo sigue los pasos y listo.&lt;br /&gt;
&lt;br /&gt;
Una vez instalado el IDE, ábrelo y ve a crear un nuevo proyecto (Archivo / Nuevo proyecto)&lt;br /&gt;
Selecciona en Categorías PHP y en Proyectos : aplicación PHP y presiona siguiente&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhupDdanE83sC-Zj_7JREtOwr-GVcPcCDjWGk8Hz7_YQdX-2DqdnZXH2ntAK2YXa6lg2qDEwubdqM-iS7PyAGz7DmIu4_C3f1zKZyTFfmQGqwapIMtUxyriCG7AfYfNA4Y5mn92J6eJC2Zk/s1600/zf_000.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;440&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhupDdanE83sC-Zj_7JREtOwr-GVcPcCDjWGk8Hz7_YQdX-2DqdnZXH2ntAK2YXa6lg2qDEwubdqM-iS7PyAGz7DmIu4_C3f1zKZyTFfmQGqwapIMtUxyriCG7AfYfNA4Y5mn92J6eJC2Zk/s640/zf_000.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;Elige &lt;b&gt;miproyecto &lt;/b&gt;como nombre&amp;nbsp; para el proyecto, y guardalo en una carpeta &lt;b&gt;DENTRO&lt;/b&gt; del directorio para las paginas web del servidor que instalaste. En el caso de Xampp, el directorio es htdocs. Si estas haciendo esto en linux puedes guardarlo en ~/public_html, pero no olvides darte los permisos correspondientes para ESA carpeta (mod rewrite y otras yerbas que iremos explicando más adelante).&lt;br /&gt;
&lt;br /&gt;
Guardaremos nuestro proyecto en la carpeta&lt;br /&gt;
C:\xampp\htdocs\miproyecto&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn91S1Evd8tO3XX_IiZ96oUUBALsGeOM-Z3KAPUZfJmSEUW6AY8ZPEVnbpF1KtzveFgmz60zgzRHNKHlgD3Sb7Sku2usmYnj0I6cSNDLUPhTSBC9LtiTPTgk8XJkA8k6NZrYzxDoB7pHhe/s1600/zf_001.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;441&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhn91S1Evd8tO3XX_IiZ96oUUBALsGeOM-Z3KAPUZfJmSEUW6AY8ZPEVnbpF1KtzveFgmz60zgzRHNKHlgD3Sb7Sku2usmYnj0I6cSNDLUPhTSBC9LtiTPTgk8XJkA8k6NZrYzxDoB7pHhe/s640/zf_001.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;presiona Siguiente&lt;/div&gt;&lt;br /&gt;
aquí veras la url desde la que ejecutaras tu proyecto (podrás cambiarla después, si lo deseas):&lt;br /&gt;
http://localhost/miproyecto/ &lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYB6Pxa73-navm9h189shngQ7BZiB4vrlDcSM7a_yCAugFwFaAwIXRhdOgHhBaGLK_2h6rs7YT7FNeFsGpFb0FbYKFN1JlhGvuthfFe5Ov7WCQzooxtqy8TY2KJZGwxx9W3l_YBBgYljrG/s1600/zf_002.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;392&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjYB6Pxa73-navm9h189shngQ7BZiB4vrlDcSM7a_yCAugFwFaAwIXRhdOgHhBaGLK_2h6rs7YT7FNeFsGpFb0FbYKFN1JlhGvuthfFe5Ov7WCQzooxtqy8TY2KJZGwxx9W3l_YBBgYljrG/s640/zf_002.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
presiona Siguiente&lt;br /&gt;
&lt;br /&gt;
En esta ventana debes indicar si quieres desarrollar este sistema usando algún framework de PHP. Nosotros marcaremos Zend Framework ( ya lo habías imaginado, ¿verdad, aprendiz perspicaz?)&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzOHceQJSzEBQ-Dczf2J4kdtorrQJR88LgjgDM-86oOBE3g7u4aZV8CzBUupsijpyYoKCi3Nu16yJPS7k5G9wCpYtPjArFFWJi7HSjC4xiCUWie1sS-IjYWVZtIGKeCbwSF-tSp4x9-1FU/s1600/zf_003.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;392&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzOHceQJSzEBQ-Dczf2J4kdtorrQJR88LgjgDM-86oOBE3g7u4aZV8CzBUupsijpyYoKCi3Nu16yJPS7k5G9wCpYtPjArFFWJi7HSjC4xiCUWie1sS-IjYWVZtIGKeCbwSF-tSp4x9-1FU/s640/zf_003.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Pero antes de apretar Siguiente, haremos clic en &lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Opciones&lt;/span&gt;&lt;/b&gt;, ese link azul al lado derecho en la ventana, pues aún no hemos configurado por primera vez nuestro ambiente de desarrollo en PHP&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Configurando al ambiente PHP&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Esto sólo se hace una vez, así que no te preocupes si te parece algo aburrido. Se trata simplemente de decirle a Netbeans dónde está nuestro zf.bat para que netbeans pueda usarlo para crear los proyectos con ZF, las clases en PHP, etc.&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw5Uf2pbTczTRDXFNTSR9ZybaH-LWgpiGMeADGRP_CZkxSV-YrHRVgI_A2QTj48MxHzsUsywcf-xasxB3Vv0X0e3AuIPtMRnndyivNZ_VFz1hU_PdULG6m8Yr0Gf9It9IE-rkBysR7TBhK/s1600/zf_004.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;548&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiw5Uf2pbTczTRDXFNTSR9ZybaH-LWgpiGMeADGRP_CZkxSV-YrHRVgI_A2QTj48MxHzsUsywcf-xasxB3Vv0X0e3AuIPtMRnndyivNZ_VFz1hU_PdULG6m8Yr0Gf9It9IE-rkBysR7TBhK/s640/zf_004.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
en la ventana que nos aparece ahora, en la pestaña Zend debemos decirle a netbeans en dónde está nuestro archivo zf.bat. Si lo agregamos al PATH de Windows (o de linux) como explicamos más arriba, Netbeans lo encontrará solo. Si no, deberemos indicárselo nosotros mismos.&lt;br /&gt;
&lt;br /&gt;
Ahora, para poder usar zf.bat desde Netbeans, debemos registrar un proveedor de ZF. Para eso, hacemos clic en el botón &lt;b&gt;Register Provider&lt;/b&gt;.&lt;br /&gt;
&lt;br /&gt;
Nos mostrará en la ventana principal del IDE un aviso diciendonos que el provider ha sido registrado con éxito. &lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;Nota: si nos sale un aviso que nos dice que no se encuentra archivo de configuración de usuario o algo por el estilo, es que nos olvidamos de ejecutar&amp;nbsp;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;zf --setup config-file&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;desde una consola. Me llevó SEIS dias descubrir eso...&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Actualización:&lt;/b&gt; si actualizamos Netbeans 6.9 o si tenemos una versión superior, si no hemos ejecutado zf --setup config-file, el ide lo hará por nosotros. Genial, ¿no? &lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Ahora volvemos a nuestra ventana&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzOHceQJSzEBQ-Dczf2J4kdtorrQJR88LgjgDM-86oOBE3g7u4aZV8CzBUupsijpyYoKCi3Nu16yJPS7k5G9wCpYtPjArFFWJi7HSjC4xiCUWie1sS-IjYWVZtIGKeCbwSF-tSp4x9-1FU/s1600/zf_003.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;392&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgzOHceQJSzEBQ-Dczf2J4kdtorrQJR88LgjgDM-86oOBE3g7u4aZV8CzBUupsijpyYoKCi3Nu16yJPS7k5G9wCpYtPjArFFWJi7HSjC4xiCUWie1sS-IjYWVZtIGKeCbwSF-tSp4x9-1FU/s640/zf_003.png&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;y presionamos &quot;siguiente&quot;.&lt;br /&gt;
&lt;br /&gt;
Internamente, Netbeans llama al comando&amp;nbsp;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;zf create project miproyecto&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
y con eso se crea toda la estructura de carpetas y archivos que ya habíamos mencionado.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-3-estructura-del.html&quot;&gt;Ahora analizaremos la estructura del proyecto.&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://angelorum.blogspot.com/feeds/3384335667375980490/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/714113637208876586/3384335667375980490?isPopup=true' title='23 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/3384335667375980490'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/3384335667375980490'/><link rel='alternate' type='text/html' href='http://angelorum.blogspot.com/2010/09/zend-framework-2-vista-general.html' title='Zend Framework 2: Crear un proyecto usando Netbeans'/><author><name>Angelorum</name><uri>http://www.blogger.com/profile/05492306132126056849</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_VvK-zBv166I/SpLtZ6qYDhI/AAAAAAAAAP8/qLgq_yl2NzU/S220/yo+sentado.jpg'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhupDdanE83sC-Zj_7JREtOwr-GVcPcCDjWGk8Hz7_YQdX-2DqdnZXH2ntAK2YXa6lg2qDEwubdqM-iS7PyAGz7DmIu4_C3f1zKZyTFfmQGqwapIMtUxyriCG7AfYfNA4Y5mn92J6eJC2Zk/s72-c/zf_000.png" height="72" width="72"/><thr:total>23</thr:total></entry><entry><id>tag:blogger.com,1999:blog-714113637208876586.post-5869790937590266838</id><published>2010-09-13T14:54:00.002-07:00</published><updated>2012-02-20T12:51:00.614-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="COMPUTACION"/><category scheme="http://www.blogger.com/atom/ns#" term="PHP"/><category scheme="http://www.blogger.com/atom/ns#" term="PROGRAMACION"/><category scheme="http://www.blogger.com/atom/ns#" term="ZEND FRAMEWORK"/><title type='text'>Zend Framework  1: Instalación</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;Zend Framework (ZF, de ahora en adelante) es un conjunto de librerías que proveen la estructura necesaria para&amp;nbsp; desarrollar un sistema en PHP de forma rápida, eficiente y con un gran ahorro de escritura de código.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://upload.wikimedia.org/wikipedia/commons/b/bf/ZendFramework-Logo.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;84&quot; src=&quot;http://upload.wikimedia.org/wikipedia/commons/b/bf/ZendFramework-Logo.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Zend Framework nos ayuda a desarrollar aplicaciones usando la &lt;a href=&quot;http://es.wikipedia.org/wiki/Modelo_Vista_Controlador&quot;&gt;&lt;b&gt;metodología MVC&lt;/b&gt;&lt;/a&gt;: Modelo-Vista-Controlador, la cual divide la estructura de un sistema en tres partes:&lt;/div&gt;&lt;ul style=&quot;text-align: justify;&quot;&gt;&lt;li&gt;&lt;b&gt;Modelo&lt;/b&gt;: los archivos (librerías, clases, funciones) relacionados con el acceso a las bases de datos&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Vista&lt;/b&gt;:&amp;nbsp; los archivos (librerías, clases, funciones)&amp;nbsp;&amp;nbsp; responsables de la presentación de la información al cliente (generalmente, las páginas con contenido HTML)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Controlador&lt;/b&gt;:&amp;nbsp; los archivos (librerías, clases, funciones) que sincronizan las dos partes anteriores y que llevan&amp;nbsp; a acabo los procesos del sistema.&lt;/li&gt;
&lt;/ul&gt;Este tutorial consta de las siguientes partes:&lt;br /&gt;
&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-1-instalacion.html&quot;&gt;Zend Framework 1:&amp;nbsp; Instalacion&lt;/a&gt; (el artículo que estás leyendo)&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-2-vista-general.html&quot;&gt;Zend Framework 2: Crear un proyecto usando Netbeans&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-3-estructura-del.html&quot;&gt;Zend Framework 3: Estructura del proyecto&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-4-controladores-y.html&quot;&gt;Zend Framework 4: Controladores y acciones&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-5-el-modelo-de-datos.html&quot;&gt;Zend Framework 5: El Modelo de datos&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-6-creando-las-paginas.html&quot;&gt;Zend Framework 6: Creando las paginas web&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-7-mostrando-las-paginas.html&quot;&gt;Zend Framework 7: Mostrando las paginas web&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/10/zend-framework-8-creando-una-plantilla.html&quot;&gt;Zend Framework 8: Creando una plantilla del sistema&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/10/zend-framework-9-traducir-mensajes-de.html&quot;&gt;Zend Framework 9: Traducir mensajes de error&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/10/zend-framework-10-trabajando-con-ajax.html&quot;&gt;Zend Framework 10: Trabajando con Ajax&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/11/zend-framework-11-sesiones-registro.html&quot;&gt;Zend Framework 11: Sesiones, registro, $this-&amp;gt;url(), multiples tablas y demases&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;http://angelorum.blogspot.com/2010/11/zend-framework-12-la-importancia-de.html&quot;&gt;Zend Framework 12: La importancia de $this-&amp;gt;render() y $this-&amp;gt;partial() en layout.phtml y las vistas&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Descargar el proyecto de &lt;a href=&quot;http://www.mediafire.com/?a0zy45x36nbmv6g&quot; target=&quot;_blank&quot;&gt;ejemplo terminado&lt;/a&gt;.&amp;nbsp; &lt;br /&gt;
&lt;ul style=&quot;text-align: justify;&quot;&gt;&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Veamos cómo va esto.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;/div&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;b&gt;1 Instalación de Zend Framework&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Antes de instalar ZF debemos tener un ambiente con un servidor HTTP, PHP y algún motor para base de datos. En este tutorial usaremos Apache, PHP 5 y Mysql 5. Aunque hay muchas formas de instalar estos tres programas, por motivos de simplicidad nosotros los instalaremos usando &lt;a href=&quot;http://www.apachefriends.org/es/xampp.html&quot;&gt;Xampp&lt;/a&gt;. (si estas usando Linux, instala los paquetes correspondientes. Es posible que incluso te permitan instalar automáticamente ZF, como en el caso de OpenSuse 11, que es la distro de linux que uso).&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Según la página oficial &lt;i&gt;&quot;XAMPP es una forma fácil de instalar la distribución Apache que contiene  MySQL, PHP y Perl. XAMPP es realmente simple de instalar y usar - basta  descargarlo, extraerlo y comienzar.&quot;&lt;/i&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;http://img216.imageshack.us/img216/6830/20xampplogotrio.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;281&quot; src=&quot;http://img216.imageshack.us/img216/6830/20xampplogotrio.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;a href=&quot;http://www.apachefriends.org/es/xampp.html&quot;&gt;Pueden descargar Xampp desde acá&lt;/a&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Para simplificar las cosas, asumiremos que lo instalamos en&lt;br /&gt;
C:\xampp&lt;br /&gt;
&lt;br /&gt;
Una vez instalado nuestro servidor apache y PHP, lo que haremos será descomprimir ZF en alguna carpeta. &lt;br /&gt;
Asumiremos que lo descomprimimos en &lt;br /&gt;
C:\ZF&lt;br /&gt;
&lt;br /&gt;
Dentro de esa carpeta veremos varias subcarpetas:&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;bin&lt;/b&gt;: contiene el interprete de linea de comandos de ZF&lt;/li&gt;
&lt;li&gt;demos&lt;/li&gt;
&lt;li&gt;externals&lt;/li&gt;
&lt;li&gt;&lt;b&gt;extras &lt;/b&gt;contiene, entre otras cosas, librerías adicionales para crear objetos de JQuery desde ZF&lt;/li&gt;
&lt;li&gt;incubator&lt;/li&gt;
&lt;li&gt;&lt;b&gt;library &lt;/b&gt;: contiene las clases en PHP que forman el Zend Framework&lt;/li&gt;
&lt;li&gt;&lt;b&gt;resources &lt;/b&gt;contiene las traducciones de los mensajes de ZF a varios lenguajes&lt;/li&gt;
&lt;li&gt;src&lt;/li&gt;
&lt;li&gt;tests&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
Lo primero que debemos hacer es colocar la ruta donde descomprimimos ZF en la variable include_path en nuestro archivo php.ini. Sin embargo, si descargamos&amp;nbsp; Xampp, nos daremos cuenta de que este ya viene con una versión de ZF pero más antigua. Para simplificar nuestro proceso de instalación, reemplazaremos la carpeta del ZF que viene con Xampp por nuestra versión más moderna de ZF.&lt;br /&gt;
&lt;br /&gt;
Para hacerlo reemplazaremos&amp;nbsp; el contenido de&lt;br /&gt;
C:\xampp\php\PEAR\Zend&lt;br /&gt;
&lt;br /&gt;
por el contenido de&lt;br /&gt;
C:\ZF \library\Zend&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
De esta forma, estamos colocando la última versión de ZF en las librerías de nuestro PHP.&lt;br /&gt;
&lt;br /&gt;
Ahora, reemplazaremos estos archivos:&lt;/div&gt;&lt;ul&gt;&lt;li&gt;C:\xampp\xampp\php\zf.bat&lt;/li&gt;
&lt;li&gt;C:\xampp\xampp\php\zf.php&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;por&lt;/div&gt;&lt;ul&gt;&lt;li&gt;C:\ZF \bin\zf.bat&lt;/li&gt;
&lt;li&gt;C:\ZF \bin\zf.php&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
Ahora, lo último que deberemos hacer es colocar la carpeta &lt;b&gt;C:\xampp\php\&lt;/b&gt; en la variable PATH de Windows, para que nos sea más fácil trabajar con él (más adelante veremos para qué nos servirá). &lt;br /&gt;
&lt;br /&gt;
Una vez hecho esto, comprobaremos si ZF está correctamente instalado. Abrimos una consola de windows (Win+R&amp;nbsp; y escribimos &#39;cmd&#39; sin comillas) y tecleamos:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;zf show version&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Debería mostrarnos:&lt;br /&gt;
&lt;b&gt;Zend Framework Version: 1.11.10&lt;/b&gt;&lt;br /&gt;
(que es la versión que yo he instalado)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
En caso de que muestre una versión anterior, revisa los pasos anteriores.&lt;br /&gt;
En caso de que al escribir zf show version la consola diga&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;b&gt;“zf show version no se reconoce como comando interno y externo... bla bla...” &lt;/b&gt;&amp;nbsp;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;asegúrate de que has incluido en la variable ambiente PATH la ruta donde se encuentra el archivo zf.bat (si estás instalando esto en Linux, obviamente deberías haber incluído el zf.sh, pero esa es harina de otro costal)&lt;br /&gt;
&lt;br /&gt;
Ahora, abramos de nuevo una consola y escribamos:&lt;br /&gt;
&lt;b&gt;zf --setup config-file&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Esto crea un archivo llamado &lt;b&gt;.zf.ini&lt;/b&gt; en nuestro directorio de usuario (en Windows esto es en&amp;nbsp; C:\Documents and Settings\tu_nombre_de_usuario y en Linux es en $HOME) donde guarda algunas preferencias personales para usar ZF como el include_path y la clase CommandProvider, que es necesaria para usar ZF dentro de Netbeans.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
¡Y listo, ya tenemos ZF instalado en nuestro computador! Fue fácil, no?&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Ahora, ¿cómo crear un proyecto usando ZF ? &lt;a href=&quot;http://angelorum.blogspot.com/2010/09/zend-framework-2-vista-general.html&quot;&gt;Lee el siguiente artículo&lt;/a&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://angelorum.blogspot.com/feeds/5869790937590266838/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/714113637208876586/5869790937590266838?isPopup=true' title='23 comentarios'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/5869790937590266838'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/714113637208876586/posts/default/5869790937590266838'/><link rel='alternate' type='text/html' href='http://angelorum.blogspot.com/2010/09/zend-framework-1-instalacion.html' title='Zend Framework  1: Instalación'/><author><name>Angelorum</name><uri>http://www.blogger.com/profile/05492306132126056849</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='24' src='http://4.bp.blogspot.com/_VvK-zBv166I/SpLtZ6qYDhI/AAAAAAAAAP8/qLgq_yl2NzU/S220/yo+sentado.jpg'/></author><thr:total>23</thr:total></entry></feed>