<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ZonaPHP &#187; Principiantes</title>
	<atom:link href="http://www.zonaphp.com/categorias/principiantes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.zonaphp.com</link>
	<description>No solo un blog, sino toda la información sobre PHP</description>
	<lastBuildDate>Sun, 04 Sep 2011 23:32:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Generadores de Documentación</title>
		<link>http://www.zonaphp.com/generadores-de-documentacion/</link>
		<comments>http://www.zonaphp.com/generadores-de-documentacion/#comments</comments>
		<pubDate>Mon, 30 Oct 2006 22:20:59 +0000</pubDate>
		<dc:creator>Webstudio</dc:creator>
				<category><![CDATA[Principiantes]]></category>

		<guid isPermaLink="false">http://www.zonaphp.com/generadores-de-documentacion/</guid>
		<description><![CDATA[Por motivos laborales, me vi en la necesidad de documentar grandes cantidades de código últimamente, un proyecto muy grande con muchos objetos ubicados en distintos directorios. Además, sumado al hecho de que es muy probable que se agreguen más programadores, la necesidad de tener una documentación del código ya no era por el mero hecho [...]]]></description>
			<content:encoded><![CDATA[<p>Por motivos laborales, me vi en la necesidad de <strong>documentar grandes cantidades de código</strong> últimamente, un proyecto muy grande con muchos objetos ubicados en distintos directorios. Además, sumado al hecho de que es muy probable que se agreguen más programadores, la necesidad de tener una documentación del código ya no era por el mero hecho de la <strong>mala memoria</strong> propia, sino que se tornaba realmente necesario para que puedan <strong>ponerse al día rápidamente</strong>.</p>
<p>Así que buscando en <strong>Google</strong>, caí rápidamente en dos proyectos, creados en PHP, para generar documentación en base al código. Uno llamado <a target="_blank" href="http://www.phpdoc.org/">PHPDocumentor</a> y el otro <a target="_blank" href="http://www.phpdoc.de/">PHPDoc</a> (el que diga que los programadores no tienen imaginación a la hora de poner nombres, que sepa que se equivoca). El primero, parece que se erigió como el standar en la generación de documentación, mientras que el segundo, era una opción interesante a la hora de encontrar un reemplazo. Lo que no esperaba era encontrarme con un leve problema: <strong><em>Ninguno de los dos funcionó en mi máquina de desarrollo, ni bien instalados</em></strong>. Muy extraño, porque recuerdo <strong>haberlos utilizado en el pasado</strong>, pero esta vez, no hubo caso. Les edité el código fuente, cambié extensiones y constantes. Nada.</p>
<p><img width="261" height="51" border="0" alt="doxygen.png" title="doxygen.png" style="margin: 10px; float: right" src="http://www.zonaphp.com/wp-content/uploads/2006/10/doxygen.png" />Así es como caí en las <strong>dos soluciones</strong> que estoy utilizando actualmente y con las cuales, tengo resuelto el tema de la documentación en el mediano plazo. El primero de ellos, es un proyecto llamado <a target="_blank" href="http://www.stack.nl/~dimitri/doxygen/"><strong>Doxygen</strong></a>, muy conocido en el ámbito de <strong>Java y C++</strong>, pero que me sorprendió gratamente al ver que también <strong>funcionaba con PHP</strong>. Mucha gente lo utiliza (por ejemplo, la gente de <a target="_blank" href="http://www.kde.org">KDE</a>) y ya veo por qué: crea la documentación separada en lista y jerarquía de clases, por archivos, módulos o estructuras de datos. Además ofrece la posibilidad de generar archivos HTML,  <a title="Microsoft Compressed HTML Help" href="http://en.wikipedia.org/wiki/Microsoft_Compressed_HTML_Help">CHM</a>, <a title="Rich Text Format" href="http://en.wikipedia.org/wiki/Rich_Text_Format">RTF</a>, <a title="Portable Document Format" href="http://en.wikipedia.org/wiki/Portable_Document_Format">PDF</a>, <a title="LaTeX" href="http://en.wikipedia.org/wiki/LaTeX">LaTeX</a>, <a title="PostScript" href="http://en.wikipedia.org/wiki/PostScript">PostScript</a> o <a title="Unix manual" href="http://en.wikipedia.org/wiki/Unix_manual">man pages</a>.</p>
<h3>PHPXref.com</h3>
<p>Esto parecería ser suficiente, si no fuera porque encontré otro generador, llamado <a target="_blank" href="http://phpxref.sourceforge.net/"><strong>PHPxRef</strong></a>, con una característica muy interesante: linkea toda llamada de un método, función, variable o constante, hacia el <strong>lugar del código donde está definido</strong> (aunque sea en otro archivo). Complementa a la perfección a Doxygen y como éste, son aplicaciones que se instalan en la PC (si usan windows, aunque también están disponibles para linux) y pueden utilizarse sin problemas, y sin tener PHP instalado. Si quieren ver un ejemplo de PHPxRef, pueden acceder a <a target="_blank" href="http://www.phpxref.com">PHPxRef.com</a>, donde hay una lista de documentación generada de algunas aplicaciones Open Source conocidas.</p>
<h3>¿Pero como se documenta el código?</h3>
<p>Esto merecería ser parte de un artículo aparte, lo cuál esto no pretende ser, pero básicamente, un standar en la documentación de código, es utilizar la sintáxis <strong>JavaDoc</strong> o <strong>PHPDoc</strong> (básicamente, lo mismo, pero con otro nombre). Si tuviéramos una clase definida en un archivo, la sintáxis PHPDoc sería:</p>
<div class="igBar"><a href="javascript:showCodeTxt('php-2');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">PHP:</span>
<div id="php-2">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">/**</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">* MiClase</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">*</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">* @uses OtraClase, Logger</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">* @package Framework</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">* @version $id$</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">* @author Pablo Rigazzi</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">*</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">* Description: Esta es una clase de ejemplo, solo para asegurarnos que todos entiendan como va la cosa.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">*</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000;">*/</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> MiClase extends OtraClase <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>Así, como verán, el comentario en vez de comenzar como usualmente lo hace, con <strong>/*</strong>. lo hace con un doble asterisco: <strong>/**</strong>. Esta sutil diferencia, permite que un programa pueda leer los comentarios cercanos a las declaraciones de clases o métodos, y agregar el contenido a la documentación. Así como ven palabras clave especiales (<strong>@uses, @author, @version, @package</strong>, etc), hay muchas otras para indicar, por ejemplo, los tipos de parámetros que recibe una función (<strong>@param</strong>) o el valor que la misma devuelve (<strong>@return</strong>). Para los más curiosos, les dejo una explicación sobre <a target="_blank" href="http://www.lab.dit.upm.es/~lprg/material/apuntes/doc/doc.htm">Como documentar código</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zonaphp.com/generadores-de-documentacion/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Crear un sistema de Rating con CSS, PHP y MySQL</title>
		<link>http://www.zonaphp.com/crear-un-sistema-de-rating-con-css-php-y-mysql/</link>
		<comments>http://www.zonaphp.com/crear-un-sistema-de-rating-con-css-php-y-mysql/#comments</comments>
		<pubDate>Tue, 17 Jan 2006 04:43:16 +0000</pubDate>
		<dc:creator>Webstudio</dc:creator>
				<category><![CDATA[Editorial]]></category>
		<category><![CDATA[Principiantes]]></category>

		<guid isPermaLink="false">http://www.zonaphp.com/?p=15</guid>
		<description><![CDATA[Supongo que todos, en mayor o menor medida, nos hemos cruzado ultimamente con un sistema de rating o votación simple, que permite valorar un recurso de manera sencilla. Es algo muy "web 2.0", tan de moda últimamente. La gente de Komodomedia publicó un tutorial explicando como lograr este efecto, utilizando CSS y una imagen, y [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/imagenes/3_big_stars.gif" width="75" height="87" alt="Estrellas" title="Estrellas" style="width: 75px; height:87px; float: right; margin: 5px"/>Supongo que todos, en mayor o menor medida, nos hemos cruzado ultimamente con un sistema de rating o votación simple, que permite valorar un recurso de manera sencilla. Es algo muy "web 2.0", tan de moda últimamente. La gente de <a href="http://komodomedia.com/">Komodomedia</a> publicó <a href="http://komodomedia.com/blog/index.php/2006/01/09/css-star-rating-part-deux/">un tutorial</a> explicando como lograr este efecto, utilizando CSS y una imagen, y <a href="http://komodomedia.com/blog/samples/star_rating/example2.htm">el resultado es muy profesional</a>.</p>
<p>Y a modo de complemento, en otro sitio, fue publicado <a href="http://slim.climaxdesigns.com/tutorial.php?section=slim&#038;id=2">una simple explicación</a> para setear un script en PHP utilizando MySQL para guardar los datos de la votación, y así luego poder mostrar los resultados utilizando el mismo ejemplo anterior. El código, hay que admitirlo, no es ninguna maravilla, pero logra el truco. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.zonaphp.com/crear-un-sistema-de-rating-con-css-php-y-mysql/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Creando Webs Modulares</title>
		<link>http://www.zonaphp.com/creando-webs-modulares/</link>
		<comments>http://www.zonaphp.com/creando-webs-modulares/#comments</comments>
		<pubDate>Fri, 21 Nov 2003 17:57:30 +0000</pubDate>
		<dc:creator>Webstudio</dc:creator>
				<category><![CDATA[Principiantes]]></category>

		<guid isPermaLink="false">http://zonaphp.local/?p=7</guid>
		<description><![CDATA[Después de embeber código PHP entre el HTML por un tiempo, cualquier principiante que esté en planes de dejar de serlo, ve cierto patrón que se repite y piensa... ¿No habrá otra manera mejor, más ordenada de hacer esto?. Pues si, si la hay y en este artículo aprenderemos una de estas maneras.]]></description>
			<content:encoded><![CDATA[<p>Después de embeber código PHP entre el HTML por un tiempo, cualquier principiante que esté en planes de dejar de serlo, ve cierto patrón que se repite y piensa... ¿No habrá otra manera mejor, más ordenada de hacer esto?. Pues si, si la hay. Y en este artículo aprenderemos una de estas maneras.<span id="more-7"></span></p>
<p><strong>Lo habitual</strong><br />
Cuando aprendemos nuestros primeros pasos con PHP, cualquier tutorial o manual que leemos, nos enseña y vanagloria las bondades de poder incluir el código PHP directamente entre el HTML. Entonces, es muy habitual ver ejemplos del tipo:</p>
<div class="igBar"><a href="javascript:showCodeTxt('php-3');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">PHP:</span>
<div id="php-3">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;html&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;head&gt;&lt;title&gt;Ejemplo de PHP embebido&lt;/title&gt;&lt;/head&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;body&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;<a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"Este texto se hace con PHP"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/body&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/html&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Y como la mente y el alma de un principiante de cualquier tema, está preparada para aprender todo lo que pueda, en el menor tiempo que pueda, toma este tipo de ejemplos como "verdades universales" y comenzamos a ver código PHP embebido entre el HTML por TODOS lados. Pero no hay que preocuparse, esto no es necesariamente malo, y todos lo hicimos en menor o mayor medida al comenzar. Es un paso necesario que hay que aprender a superar. <img src='http://www.zonaphp.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Luego de un tiempo, y después de haber leido un poco más, aprendemos que todas las partes comunes de código que son repetitivas, pueden residir en archivos separados y ser "Incluidas" en nuestro código con tan solo el uso de una función:</p>
<div class="igBar"><a href="javascript:showCodeTxt('php-4');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">PHP:</span>
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;html&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;head&gt;&lt;title&gt;Ejemplo de PHP embebido&lt;/title&gt;&lt;/head&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;body&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?</span> <span style="color:#616100;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'includes/header.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;table&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&lt;tr&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&lt;td width=<span style="color:#FF0000;">"120"</span>&gt;&lt;? <span style="color:#616100;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'includes/menu.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; ?&gt;&lt;/td&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp;&lt;td&gt;Aqui va el contenido del sitio web propiamente dicho. Recordar que es terriblemente MALO y PERJUDICIAL para la salud de su sitio, utilizar archivos externos con extensión <span style="color:#FF0000;">".inc"</span>&lt;/td&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;&lt;/tr&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?</span> <span style="color:#616100;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'includes/footer.php'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#000000; font-weight:bold;">?&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/table&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/body&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/html&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Entonces, ese es el momento en que <b>include()</b> se convierte en nuestro mejor amigo y descubrimos, fascinados, como podemos lograr una verdadera mejora en el mantenimiento de nuestros sitios, al tener que modificar 1 solo archivo y que este cambio, se vea reflejado en TODAS las páginas que incluyan ese archivo. Hemos, señoras y señores, alcanzado el Nirvana.</p>
<p>Pero, lamento decepcionarlos, ningún estado de felicidad suprema es permanente. Luego de un tiempo, y a medida que seguimos utilizando este método, de repente nos vamos dando cuenta que algo simplemente no cuadra. Si bien el anterior método del include() nos salvó en su debido momento, nos vamos dando cuenta que para crear una nueva página, es necesario repetir muchas veces los include() que llaman a las partes comunes de nuestro sitio. Esto sin contar que si, por arte de magia o capricho de un jefe/cliente, la cabecera de nuestro sitio pasa de ser header.php a cabecera.php, deberiamos modificar uno a uno todos los archivos que hagan un llamado a "header.php" y hacer el reemplazo.</p>
<p>Es en este punto, donde cientos de programadores, todos los años se hacen la misma pregunta: ¿No habrá una manera mejor de hacer esto?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zonaphp.com/creando-webs-modulares/feed/</wfw:commentRss>
		<slash:comments>103</slash:comments>
		</item>
		<item>
		<title>Crear un foro en PHP y Mysql [revisado]</title>
		<link>http://www.zonaphp.com/crear-un-foro-en-php-y-mysql-revisado/</link>
		<comments>http://www.zonaphp.com/crear-un-foro-en-php-y-mysql-revisado/#comments</comments>
		<pubDate>Sun, 15 Jun 2003 04:28:50 +0000</pubDate>
		<dc:creator>Webstudio</dc:creator>
				<category><![CDATA[Principiantes]]></category>

		<guid isPermaLink="false">http://zonaphp.local/?p=8</guid>
		<description><![CDATA[En esta segunda versión del tutorial original, crearemos un foro desde cero aprendiendo a separar la programación del diseño, y modularizando  nuestra aplicación para que sea simple de configurar y de adaptar.]]></description>
			<content:encoded><![CDATA[<p>En esta segunda versión del tutorial original, crearemos un foro desde cero aprendiendo a separar la programación del diseño, y modularizando  nuestra aplicación para que sea simple de configurar y de adaptar.<span id="more-8"></span></p>
<p><strong>La Estructura</strong></p>
<p>Primero y antes que nada, para aquellos que no deseen tipear todo el contenido del artículo en sus editores de texto, les dejo un link al <a href="http://zonaphp.com/archivos/foro.zip">código del foro</a> para que descarguen y puedan revisar mientras leen el artículo.</p>
<p>A continuación debemos preparar la tabla en la base de datos que contendrá todos los temas de nuestro foro. Lo que esta tabla tendrá, es la información de nuestros mensajes, el autor del mismo, y otros datos que servirán para identificar a que Tema pertenece un mensaje. Pero mejor, veamos la estructura propuesta :</p>
<div class="igBar"><a href="javascript:showCodeTxt('sql-5');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">SQL:</span>
<div id="sql-5">
<div class="sql">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> <span style="color: #ff0000;">`foro`</span> <span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`id`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">7</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`autor`</span> varchar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">200</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">''</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`titulo`</span> varchar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">200</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">''</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`mensaje`</span> text <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`fecha`</span> datetime <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0000-00-00 00:00:00'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`respuestas`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">11</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0'</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`identificador`</span> int<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#800000;">7</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #ff0000;">'0'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #ff0000;">`ult_respuesta`</span> datetime <span style="color: #993333; font-weight: bold;">DEFAULT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #ff0000;">`id`</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#41;</span> TYPE=MyISAM; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Veamos en detalle que campos tendrá nuestra tabla de Foros:</p>
<ul>
<li><strong>id</strong> : Será e identificador principal de la tabla. Sirve para diferenciar cada uno de los mensajes.</li>
<li><strong>autor</strong> : el autor del mensaje.</li>
<li><strong>titulo</strong> : el titulo que tendrá el mensaje. Si este mensaje es el iniciador de un tema, será el que mostrará en el home del Foro.</li>
<li><strong>mensaje</strong> : El mensaje en si mismo.</li>
<li><strong>fecha</strong> : un campo DATETIME que indicará en que fecha se ha publicado este mensaje.</li>
<li><strong>respuestas</strong> : Si este mensaje es el iniciador de un tema, aqui se acumularán la cantidad de respuestas que reciba.</li>
<li><strong>identificador</strong> : este campo guarda el valor del id del mensaje que se está respondiendo. Si el mensaje es iniciador de un tema, entonces este campo valdrá cero.</li>
<li><strong>ult_respuesta</strong> : si el mensaje es iniciador de tema, aqui se actualizará valor de acuerdo con la fecha de la última respuesta que haya recibido. Sirve para poder mantener un orden en los foros.</li>
</ul>
<p>La sentencia SQL anterior, pueden guardarla en un archivo.sql y correrla en su base de datos desde el <a href="http://phpmyadmin.sourceforge.net">phpMyAdmin</a>, o si lo prefieren, pueden ingresarla linea por linea en un cliente de texto de mySQL ( como el mySQL monitor). Una vez que hayan creado la tabla en su base de datos, entonces podemos avanzar al siguiente paso.</p>
<p>Antes de ponernos a programar cualquier parte del foro, vamos a encargarnos de hacer un pequeño script que realice una tarea que vamos a repetir mucho, y que es conectarnos a la base de datos. Este script lo incluiremos en cada página en la que tengamos que acceder a la base de datos:</p>
<p><strong><em>configuracion.php</em></strong>
<div class="igBar"><a href="javascript:showCodeTxt('php-6');">PLAIN TEXT</a></div>
<div class="syntax_hilite"><span style="color:#000000; font-weight:bold;">PHP:</span>
<div id="php-6">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&amp;lt;?php</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$bd_host</span> = <span style="color:#FF0000;">"localhost"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$bd_usuario</span> = <span style="color:#FF0000;">"user"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$bd_password</span> = <span style="color:#FF0000;">"password"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$bd_base</span> = <span style="color:#FF0000;">"nuestra_bd"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$con</span> = <a href="http://www.php.net/mysql_connect"><span style="color:#000066;">mysql_connect</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$bd_host</span>, <span style="color:#0000FF;">$bd_usuario</span>, <span style="color:#0000FF;">$bd_password</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/mysql_select_db"><span style="color:#000066;">mysql_select_db</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$bd_base</span>, <span style="color:#0000FF;">$con</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="color:#000000; font-family: 'Courier New', Courier, monospace; font-weight: normal;">?&amp;gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p>Cómo vemos, no hay gran ciencia en este script, tan solo unas variables conteniendo la configuración de nuestra base de datos, y el código mínimo y necesario para conectarnos y guardar el recurso de conexión en una variable <strong>$con</strong> que luego utilizaremos cuando hagamos nuestras consultas.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.zonaphp.com/crear-un-foro-en-php-y-mysql-revisado/feed/</wfw:commentRss>
		<slash:comments>166</slash:comments>
		</item>
	</channel>
</rss>

