<?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>Isern Palaus &#187; jQuery</title>
	<atom:link href="http://blog.ipalaus.es/tag/jquery/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.ipalaus.es</link>
	<description>PHP, CodeIgniter y jQuery</description>
	<lastBuildDate>Sat, 10 Apr 2010 13:10:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>jQuery plugin: TipTip, tooltips personalizadas</title>
		<link>http://blog.ipalaus.es/jquery-plugin-tiptip-tooltips-personalizadas</link>
		<comments>http://blog.ipalaus.es/jquery-plugin-tiptip-tooltips-personalizadas#comments</comments>
		<pubDate>Mon, 22 Mar 2010 00:44:35 +0000</pubDate>
		<dc:creator>Isern Palaus</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tooltip]]></category>

		<guid isPermaLink="false">http://blog.ipalaus.es/?p=51</guid>
		<description><![CDATA[ TipTip es una manera sencilla de crear tips cross-browser que además destaca por no hacer uso ninguno de imágenes y perfectamente adaptado para ser personalizado vía CSS. Se ajusta automáticamente a las medidas de nuestro navegador mostrando siempre bien el Tip (en caso de que modifiquemos el tamaño de la ventana, no dejará de <a href="http://blog.ipalaus.es/jquery-plugin-tiptip-tooltips-personalizadas" class="more-link">Más &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.ipalaus.es/wp-content/uploads/2010/03/jquery-tiptip.png"><img class="alignleft size-medium wp-image-52" title="jQuery plugin: TipTip" src="http://blog.ipalaus.es/wp-content/uploads/2010/03/jquery-tiptip-300x125.png" alt="" width="300" height="125" /></a><strong> TipTip</strong> es una manera sencilla de crear tips cross-browser que además destaca por no hacer uso ninguno de imágenes y perfectamente adaptado para ser personalizado vía CSS. Se ajusta automáticamente a las medidas de nuestro navegador mostrando siempre bien el Tip (en caso de que modifiquemos el tamaño de la ventana, no dejará de mostrase).</p>
<p>Su configuración es más bien sencilla, como la gran mayoría de estos plugins teniendo varias opciones de personalización y de <em>callbacks</em>:</p>
<div id="wpshdo_1" class="wp-synhighlighter-outer"><div id="wpshdt_1" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_1"></a><a id="wpshat_1" class="wp-synhighlighter-title" href="#codesyntax_1"  onClick="javascript:wpsh_toggleBlock(1)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_1" onClick="javascript:wpsh_code(1)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_print(1)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_1" onClick="javascript:wpsh_about(1)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_1" class="wp-synhighlighter-inner" style="display: block;">$<span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;.ejemplo&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">tipTip</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<div id="wpshdo_2" class="wp-synhighlighter-outer"><div id="wpshdt_2" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_2"></a><a id="wpshat_2" class="wp-synhighlighter-title" href="#codesyntax_2"  onClick="javascript:wpsh_toggleBlock(2)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_2" onClick="javascript:wpsh_code(2)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_print(2)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_2" onClick="javascript:wpsh_about(2)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_2" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://blog.ipalaus.es&quot;</span> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;ejemplo&quot;</span> <span style="color: #000066;">title</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Blog personal de Isern Palaus&quot;</span>&gt;</span>Isern Palaus<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/a.html"><span style="color: #000000; font-weight: bold;">a</span></a>&gt;</span></div></div>
<p><span id="more-51"></span></p>
<p>En el siguiente vídeo en inglés, y del creador del plugin para jQuery, podemos ver varios ejemplos de su uso:</p>
<p><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="338" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://vimeo.com/moogaloop.swf?clip_id=8508658&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=c9ff23&amp;fullscreen=1" /><embed type="application/x-shockwave-flash" width="600" height="338" src="http://vimeo.com/moogaloop.swf?clip_id=8508658&amp;server=vimeo.com&amp;show_title=0&amp;show_byline=0&amp;show_portrait=0&amp;color=c9ff23&amp;fullscreen=1" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>Descargar | <a href="http://blog.ipalaus.es/dm.php?id=7">tipTipv12.zip</a><br />
Página oficial | <a href="http://code.drewwilson.com/entry/tiptip-jquery-plugin">TipTip jQuery Plugin</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ipalaus.es/jquery-plugin-tiptip-tooltips-personalizadas/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jQuery Plugin: js-columns columnas al estilo periódico</title>
		<link>http://blog.ipalaus.es/jquery-plugin-js-column-columnas-al-estilo-periodico</link>
		<comments>http://blog.ipalaus.es/jquery-plugin-js-column-columnas-al-estilo-periodico#comments</comments>
		<pubDate>Sat, 20 Mar 2010 16:46:49 +0000</pubDate>
		<dc:creator>Isern Palaus</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[columns]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[text]]></category>

		<guid isPermaLink="false">http://blog.ipalaus.es/?p=45</guid>
		<description><![CDATA[js-columns es un plugin para jQuery que nos permite crear columnas al estilo de un periódico fácilmente. Mientras esperamos la total integración de CSS3 que nos permitirá hacerlo directamente desde nuestra hoja de estilos, esta es una buena opción.
Aún está un poco verde en su primera versión (31/01/2010) nos permite mostrar columnas dentro de un contenedor <a href="http://blog.ipalaus.es/jquery-plugin-js-column-columnas-al-estilo-periodico" class="more-link">Más &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><strong><a href="http://blog.ipalaus.es/wp-content/uploads/2010/03/jquer-plugin-columnas.png"><img class="alignright size-medium wp-image-46" title="jQuery Plugin: js-columns" src="http://blog.ipalaus.es/wp-content/uploads/2010/03/jquer-plugin-columnas-300x147.png" alt="" width="300" height="147" /></a>js-columns</strong> es un plugin para jQuery que nos permite crear columnas al estilo de un periódico fácilmente. Mientras esperamos la total integración de CSS3 que nos permitirá hacerlo directamente desde nuestra hoja de estilos, esta es una buena opción.</p>
<p>Aún está un poco verde en su primera versión (31/01/2010) nos permite mostrar columnas dentro de un contenedor (es decir, div) y crea una paginación en caso de que el contenido sea más grande que el contenedor, y el mismo nos permite movernos en él sin tener que actualizar la página. También se adapta a la resolución de nuestro navegador en caso de que modifiquemos el tamaño de la ventana, creando el paginador de nuevo si hiciera falta. A parte, nos deja añadir imágenes fácilmente y nos cuadra la misma con las columnas creadas.</p>
<p>En el mismo rar nos viene una página de ejemplo, pero para crear un div con columnas lo haremos así:</p>
<div id="wpshdo_3" class="wp-synhighlighter-outer"><div id="wpshdt_3" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_3"></a><a id="wpshat_3" class="wp-synhighlighter-title" href="#codesyntax_3"  onClick="javascript:wpsh_toggleBlock(3)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_3" onClick="javascript:wpsh_code(3)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_print(3)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_3" onClick="javascript:wpsh_about(3)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_3" class="wp-synhighlighter-inner" style="display: block;">$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'.columna'</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">columns</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span>paging<span style="color: #339933;">:</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Descargar | <a href="http://blog.ipalaus.es/dm.php?id=6">js-columns-0.1.zip</a><br />Página oficial | <a href="http://code.google.com/p/js-columns/w/list">js-columns</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ipalaus.es/jquery-plugin-js-column-columnas-al-estilo-periodico/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AJAX Login con jQuery y CodeIgniter &#8211; v2 + archivos</title>
		<link>http://blog.ipalaus.es/ajax-login-con-jquery-y-codeigniter-v2-archivos</link>
		<comments>http://blog.ipalaus.es/ajax-login-con-jquery-y-codeigniter-v2-archivos#comments</comments>
		<pubDate>Tue, 01 Dec 2009 21:29:21 +0000</pubDate>
		<dc:creator>Isern Palaus</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ajax login]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[login]]></category>

		<guid isPermaLink="false">http://blog.ipalaus.es/?p=18</guid>
		<description><![CDATA[Hola amigos,
Esta es la revisión del tutorial que escribí hace más de un año. Es prácticamente lo mismo pero con todos los archivos que necesitas en un zip, a parte de ciertas modificaciones necesarias en el procesado de los datos.
Para esa gente que esta buscando un sistema de usuarios funcional con registro, tengo que decir que no <a href="http://blog.ipalaus.es/ajax-login-con-jquery-y-codeigniter-v2-archivos" class="more-link">Más &#62;</a>]]></description>
			<content:encoded><![CDATA[<p>Hola amigos,</p>
<p>Esta es la revisión del tutorial que escribí hace más de un año. Es prácticamente lo mismo pero con todos los archivos que necesitas en un zip, a parte de ciertas modificaciones necesarias en el procesado de los datos.</p>
<p>Para esa gente que esta buscando un sistema de usuarios funcional con registro, tengo que decir que no tengo tiempo para programarlo todo por mi mismo para este manual. De este modo, como he hecho desde que comencé en CodeIgniter, usaremos una aplicación de terceros: un sistema completo de usuarios. Lo he basado en el trabajo de Popcorn, llamado &#8216;Redux Authentication&#8217; (v2 beta).<br />
Lo primero que necesitamos es descargar la librería de Redux. Accedemos al proyecto en Google Code y lo descargamos <a href="http://code.google.com/p/reduxauth/" target="_self">aquí</a>. Puedes ir a la <a href="http://codeigniter.com/forums/viewthread/90254/">entrada oficial</a> en el foro de CodeIgniter para preguntar sobre la misma.<br />
Cuando descargues la librería, verás que dentro existe una carpeta llamada &#8216;Example Application&#8217;. Usaremos esta aplicación pero necesitamos actualizarla a la ultima versión de CodeIgniter, sino no nos funcionará. Ten en cuenta, que en el pack final ya esta actualizado pero es mucho mejor si lo haces por tu propio pie, aprenderás más.<br />
Es muy fácil actualizarlo: descargas <a href="http://www.codeigniter.com/">CodeIgniter</a> y lo descomprimes. Ve a &#8216;Example Application&#8217;, renombra la carpeta a ajaxlogin (usaré este nombre en los ejemplos). Entra en la misma y seguidamente a /system. Borra <strong>todas</strong> las carpetas excepto <strong>application</strong>, donde esta la aplicación. Accede a la versión descarga de CodeIgniter y copia todas las carpetas que has eliminado (todas menos application). Puedes encontrar la guía oficial de CodeIgniter para la actualización <a href="http://codeigniter.com/user_guide/installation/upgrading.html">aquí</a>.<br />
Entonces, instala la base de datos y configurala. Lo primero que tienes que hacer es añadir un grupo llamado &#8216;members&#8217; en la tabla de grupos:</p>
<div id="wpshdo_4" class="wp-synhighlighter-outer"><div id="wpshdt_4" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_4"></a><a id="wpshat_4" class="wp-synhighlighter-title" href="#codesyntax_4"  onClick="javascript:wpsh_toggleBlock(4)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_4" onClick="javascript:wpsh_code(4)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_print(4)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_4" onClick="javascript:wpsh_about(4)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_4" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #993333; font-weight: bold;">INSERT</span> <span style="color: #993333; font-weight: bold;">INTO</span> groups <span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">`id`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`name`</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">`description`</span><span style="color: #66cc66;">&#41;</span> <span style="color: #993333; font-weight: bold;">VALUES</span> <span style="color: #66cc66;">&#40;</span><span style="color: #993333; font-weight: bold;">NULL</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'member'</span><span style="color: #66cc66;">,</span> <span style="color: #ff0000;">'Members'</span><span style="color: #66cc66;">&#41;</span></div></div>
<p><span id="more-18"></span><br />
En el archivo config/redux_auth.php verás que hay una opción para configurar el grupo por defecto. En la base de datos no tenemos datos de modo que necesitamos añadir un grupo por defecto y modificar el archivo de configuración para que lo detecte. Otra recomendación para este mismo archivo es cambiar la configuración de activación a FALSE porque no funciona del todo. Hay otras variables que puedes cambiar, como el método de entrada (username, email&#8230;). He elegido el e-mail, que es el que viene por defecto.  Cambiar para que sea el usuario no es difícil. Probarlo.<br />
<div id="wpshdo_5" class="wp-synhighlighter-outer"><div id="wpshdt_5" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_5"></a><a id="wpshat_5" class="wp-synhighlighter-title" href="#codesyntax_5"  onClick="javascript:wpsh_toggleBlock(5)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_5" onClick="javascript:wpsh_code(5)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_print(5)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_5" onClick="javascript:wpsh_about(5)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_5" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #000088;">$config</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email_activation'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span></div></div><br />
Ahora puedes ir a tu página, configurar otras cosas que harías en cualquier aplicación&#8230;<br />
Lo primero que haremos será crear un usuario. Esto lo tienes que hacer desde la página, claro. Accede y lo verás claro. Después, intenta acceder. Serás redirigido al apartado status y verás <strong>bool(true)</strong> si has entrado correctamente. ¡Ahora es hora de programar nuestra aplicación en AJAX!<br />
Ve a <strong>/system/application/views/template.php</strong> y, entre  y  añade la <a href="http://www.jquery.com/">librería de jQuery que has descargado</a>:</p>
<div id="wpshdo_6" class="wp-synhighlighter-outer"><div id="wpshdt_6" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_6"></a><a id="wpshat_6" class="wp-synhighlighter-title" href="#codesyntax_6"  onClick="javascript:wpsh_toggleBlock(6)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_6" onClick="javascript:wpsh_code(6)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_print(6)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_6" onClick="javascript:wpsh_about(6)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_6" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;&lt;?php echo base_url().'assets/js/jquery-1.3.2.min.js'; ?&gt;&quot;</span><span style="color: #339933;">&gt;&lt;/</span>script<span style="color: #339933;">&gt;</span><br />
<span style="color: #339933;">&lt;</span>script type<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;text/javascript&quot;</span> src<span style="color: #339933;">=&lt;?</span>php echo base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #3366CC;">'assets/js/ajaxlogin.js'</span><span style="color: #339933;">;</span> <span style="color: #339933;">?&gt;</span><span style="color: #3366CC;">&quot;&gt;&lt;/script&gt;</span></div></div>
<p>En este caso, la diferencia con el otro script, es que usaremos la función de Redux para el login y esto optimizará nuestro código ya que esta mucho más depurado. En el controller welcome añadiremos dos funciones:</p>
<div id="wpshdo_7" class="wp-synhighlighter-outer"><div id="wpshdt_7" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_7"></a><a id="wpshat_7" class="wp-synhighlighter-title" href="#codesyntax_7"  onClick="javascript:wpsh_toggleBlock(7)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_7" onClick="javascript:wpsh_code(7)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_print(7)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_7" onClick="javascript:wpsh_about(7)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_7" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #000000; font-weight: bold;">function</span> _check_login<span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">redux_auth</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">login</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> ajaxLogin<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
<span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">load</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">library</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'validation'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loginemail</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">input</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">post</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Email Address'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'trim|required|callback__check_login'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">set_rules</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'Password'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'trim|required'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">form_validation</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>    <span style="color: #0000ff;">'success'</span> <span style="color: #339933;">=&gt;</span>    <span style="color: #0000ff;">'no'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'message'</span> <span style="color: #339933;">=&gt;</span>    <span style="color: #0000ff;">'The email or password you provided are wrong.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/json_encode"><span style="color: #990000;">json_encode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>    <span style="color: #0000ff;">'success'</span> <span style="color: #339933;">=&gt;</span>    <span style="color: #0000ff;">'yes'</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0000ff;">'welcome'</span> <span style="color: #339933;">=&gt;</span>    <span style="color: #0000ff;">'Welcome '</span><span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">loginemail</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'!'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/json_encode"><span style="color: #990000;">json_encode</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000088;">$output</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/str_replace"><span style="color: #990000;">str_replace</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Para entender el código: la primera función, _check_login(), usa el modelo redux_auth_model.php para validar el correo y la contraseña que hemos seleccionado. Para más información mira el modelo en la carpeta models. Si la información procesada es correcta devuelve TRUE, sino FALSE. En caso de que devuelva TRUE, la aplicación crea la sesión con nuestro e-mail. Si necesitas alguna cosa más, edita el modelo.</p>
<p>La segunda función es un mix de la función de login de Redux y mi función de AJAX. Toma los dos inputs y los valida. El primero, correo electrónico, usa la función callback a la función _check_login(). Si la información no es correcta, o sucede algún problema, devuelve FALSE. Entonces pasaremos la información a la función AJAX y la codificaremos con JSON. La información codificada se muestra tal que así: { &#8220;success&#8221;: &#8220;no&#8221;, &#8220;message&#8221;: &#8220;The email or password you provided are wrong.&#8221; }.</p>
<p>Hay que tener en cuenta que uso $this-&gt;password y $this-&gt;loginemail. Estas variables tienen que ser definidas en el inicio el controlador, así:</p>
<div id="wpshdo_8" class="wp-synhighlighter-outer"><div id="wpshdt_8" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_8"></a><a id="wpshat_8" class="wp-synhighlighter-title" href="#codesyntax_8"  onClick="javascript:wpsh_toggleBlock(8)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_8" onClick="javascript:wpsh_code(8)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_print(8)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_8" onClick="javascript:wpsh_about(8)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_8" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #000000; font-weight: bold;">class</span> Welcome <span style="color: #000000; font-weight: bold;">extends</span> Controller <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$password</span>     <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$loginemail</span>    <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">NULL</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #009933; font-style: italic;">/**<br />
&nbsp; &nbsp; &nbsp;* index<br />
&nbsp; &nbsp; &nbsp;*<br />
&nbsp; &nbsp; &nbsp;* @return void<br />
&nbsp; &nbsp; &nbsp;* @author Mathew<br />
&nbsp; &nbsp; **/</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span> index<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; redirect<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'welcome/status'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #339933;">...</span></div></div>
<p>Perfecto! Ahora modificaremos el login. Como sabes, la mejor manera de crear un formulario en CodeIgniter es accediendo a su user guide. De este modo, abre<strong> /views/login.php</strong>. Cuando tenemos un tenemos un formulario de login normalmente solo lo mostramos cuando el usuario no esta identificado. En el ejemplo de la librería Redux esto no pasa y tenemos que modificarlo. La manera es comprobar si existe el item &#8216;identity&#8217; en la session. Añade al principio del archivo:</p>
<div id="wpshdo_9" class="wp-synhighlighter-outer"><div id="wpshdt_9" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_9"></a><a id="wpshat_9" class="wp-synhighlighter-title" href="#codesyntax_9"  onClick="javascript:wpsh_toggleBlock(9)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_9" onClick="javascript:wpsh_code(9)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_print(9)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_9" onClick="javascript:wpsh_about(9)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_9" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">session</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">userdata</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">item</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'identity'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;&lt;h1&gt;You're aready logged in!&lt;/h1&gt;&quot;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &lt;h1&gt;Login&lt;/h1&gt;</div></div>
<p>Esto comprobará si existe. Al final del archivo, añade:</p>
<div id="wpshdo_10" class="wp-synhighlighter-outer"><div id="wpshdt_10" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_10"></a><a id="wpshat_10" class="wp-synhighlighter-title" href="#codesyntax_10"  onClick="javascript:wpsh_toggleBlock(10)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_10" onClick="javascript:wpsh_code(10)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_print(10)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_10" onClick="javascript:wpsh_about(10)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_10" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #000000; font-weight: bold;">?&gt;</span></div></div>
<p>Compruébalo. Accede y vuelve al formulario de identificación. Mostrará <strong>You&#8217;re already logged in</strong>.<br />
Tenemos que añadir algunas lineas más al archivo login.php. Cambia el <strong>form_open()</strong> y añade un id, añade un id a la tabla y añade un id a las divs extras que usaremos para mostrar los errores o sucesos de la aplicación AJAX. Es necesario que jQuery los identifique y eso lo hacemos con los ids.</p>
<div id="wpshdo_11" class="wp-synhighlighter-outer"><div id="wpshdt_11" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_11"></a><a id="wpshat_11" class="wp-synhighlighter-title" href="#codesyntax_11"  onClick="javascript:wpsh_toggleBlock(11)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_11" onClick="javascript:wpsh_code(11)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_print(11)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_11" onClick="javascript:wpsh_about(11)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_11" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> form_open<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'welcome/login'</span><span style="color: #339933;">,</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'userlogin'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
<br />
&lt;table id=&quot;loginform&quot;&gt;<br />
<br />
&lt;div id=&quot;logged&quot;&gt;&lt;div&gt;<br />
<br />
&lt;div id=&quot;loginerror&quot;&gt;&lt;/div&gt;</div></div>
<p>He añadido estas dos últimas &lt;div&gt;&#8217; despues del <strong>form_close()</strong>.</p>
<p>A parte, haz estos cambios:<br />
<div id="wpshdo_12" class="wp-synhighlighter-outer"><div id="wpshdt_12" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_12"></a><a id="wpshat_12" class="wp-synhighlighter-title" href="#codesyntax_12"  onClick="javascript:wpsh_toggleBlock(12)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_12" onClick="javascript:wpsh_code(12)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_print(12)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_12" onClick="javascript:wpsh_about(12)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_12" class="wp-synhighlighter-inner" style="display: block;">&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> form_input<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #339933;">,</span> set_value<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;</div></div></p>
<p>Por:</p>
<div id="wpshdo_13" class="wp-synhighlighter-outer"><div id="wpshdt_13" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_13"></a><a id="wpshat_13" class="wp-synhighlighter-title" href="#codesyntax_13"  onClick="javascript:wpsh_toggleBlock(13)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_13" onClick="javascript:wpsh_code(13)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_print(13)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_13" onClick="javascript:wpsh_about(13)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_13" class="wp-synhighlighter-inner" style="display: block;">&lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;email&quot; value=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> set_value<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; id=&quot;email&quot; /&gt;&lt;/td&gt;</div></div>
<p>Y:</p>
<div id="wpshdo_14" class="wp-synhighlighter-outer"><div id="wpshdt_14" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_14"></a><a id="wpshat_14" class="wp-synhighlighter-title" href="#codesyntax_14"  onClick="javascript:wpsh_toggleBlock(14)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_14" onClick="javascript:wpsh_code(14)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_print(14)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_14" onClick="javascript:wpsh_about(14)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_14" class="wp-synhighlighter-inner" style="display: block;">&lt;td&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> form_password<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'password'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/td&gt;</div></div>
<p>Por:</p>
<div id="wpshdo_15" class="wp-synhighlighter-outer"><div id="wpshdt_15" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_15"></a><a id="wpshat_15" class="wp-synhighlighter-title" href="#codesyntax_15"  onClick="javascript:wpsh_toggleBlock(15)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_15" onClick="javascript:wpsh_code(15)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_15" onClick="javascript:wpsh_print(15)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_15" onClick="javascript:wpsh_about(15)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_15" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #339933;">&lt;</span>td<span style="color: #339933;">&gt;&lt;</span>input type<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> name<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> value<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;&quot;</span> id<span style="color: #339933;">=</span><span style="color: #0000ff;">&quot;password&quot;</span> <span style="color: #339933;">/&gt;&lt;/</span>td<span style="color: #339933;">&gt;</span></div></div>
<p>Ahora es tiempo del archivo javascript. Recuerda que antes hemos añadido la librería de jQuery. Crea un archivo que se llame <strong>ajaxlogin.js</strong> en <strong>/assets/js/</strong>. Para usar el ajaxForm necesitas un plugin. Lo puedes descargar <a href="http://www.malsup.com/jquery/form/#download">aquí</a>. Lo añadimos igual que hemos hecho los dos del principio, en <strong>/views/template.php</strong>:</p>
<div id="wpshdo_16" class="wp-synhighlighter-outer"><div id="wpshdt_16" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_16"></a><a id="wpshat_16" class="wp-synhighlighter-title" href="#codesyntax_16"  onClick="javascript:wpsh_toggleBlock(16)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_16" onClick="javascript:wpsh_code(16)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_16" onClick="javascript:wpsh_print(16)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_16" onClick="javascript:wpsh_about(16)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_16" class="wp-synhighlighter-inner" style="display: block;">&lt;script type=&quot;text/javascript&quot; src=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> base_url<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'assets/js/jquery.form.js'</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot;&gt;&lt;/script&gt;</div></div>
<p>Ahora, escribe en <strong>ajaxlogin.js</strong>:</p>
<div id="wpshdo_17" class="wp-synhighlighter-outer"><div id="wpshdt_17" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_17"></a><a id="wpshat_17" class="wp-synhighlighter-title" href="#codesyntax_17"  onClick="javascript:wpsh_toggleBlock(17)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_17" onClick="javascript:wpsh_code(17)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_17" onClick="javascript:wpsh_print(17)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_17" onClick="javascript:wpsh_about(17)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_17" class="wp-synhighlighter-inner" style="display: block;">$<span style="color: #009900;">&#40;</span>document<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ready<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#userlogin&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>ajaxForm<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; type<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;POST&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; url<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;http://localhost/ajaxlogin/index.php/welcome/ajaxLogin&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; dataType<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;json&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; data<span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;email=&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#email&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #0000ff;">&quot;&amp;amp;password;=&quot;</span><span style="color: #339933;">+</span>$<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>val<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; success<span style="color: #339933;">:</span> updateLogin<br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<div id="_mcePaste">Ten en cuenta que es posible que tengas que cambiar la URL.  Yo lo uso en mi localhost y con el alias ajaxlogin. Mismamente, uso el index.php y el controlador welcome. Debes modificarlo si es necesario.</div>
<div id="_mcePaste">Ahora mismo, el script funcionaria pero debemos añadirle un complemento&#8230; la función que llama ajaxForm cuando se ejecuta:</div>
<p>Ten en cuenta que es posible que tengas que cambiar la URL.  Yo lo uso en mi localhost y con el alias ajaxlogin. Mismamente, uso el index.php y el controlador welcome. Debes modificarlo si es necesario.<br />
Ahora mismo, el script funcionaria pero debemos añadirle un complemento&#8230; la función que llama ajaxForm cuando se ejecuta:</p>
<div id="wpshdo_18" class="wp-synhighlighter-outer"><div id="wpshdt_18" class="wp-synhighlighter-expanded"><table border="0" width="100%"><tr><td align="left" width="80%"><a name="#codesyntax_18"></a><a id="wpshat_18" class="wp-synhighlighter-title" href="#codesyntax_18"  onClick="javascript:wpsh_toggleBlock(18)" title="Click to show/hide code block">Code block</a></td><td align="right"><a href="#codesyntax_18" onClick="javascript:wpsh_code(18)" title="Show code only"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/code.png" /></a>&nbsp;<a href="#codesyntax_18" onClick="javascript:wpsh_print(18)" title="Print code"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/printer.png" /></a>&nbsp;<a href="#codesyntax_18" onClick="javascript:wpsh_about(18)" title="Show plugin information"><img border="0" style="border: 0 none" src="http://blog.ipalaus.es/wp-content/plugins/wp-synhighlight/themes/default/images/info.gif" /></a>&nbsp;</td></tr></table></div><div id="wpshdi_18" class="wp-synhighlighter-inner" style="display: block;"><span style="color: #000000; font-weight: bold;">function</span> updateLogin<span style="color: #009900;">&#40;</span>data<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#logged'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>html<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#logged'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>hide<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#loginform&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>fadeOut<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slow&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>data<span style="color: #339933;">.</span>success <span style="color: #339933;">==</span> <span style="color: #0000ff;">'yes'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#logged'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>html<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">.</span>welcome<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>fadeIn<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>data<span style="color: #339933;">.</span>success <span style="color: #339933;">==</span> <span style="color: #0000ff;">'no'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'#loginerror'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>html<span style="color: #009900;">&#40;</span>data<span style="color: #339933;">.</span>message<span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>fadeIn<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>fadeOut<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slow&quot;</span><span style="color: #339933;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;#loginform&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span>fadeIn<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;slow&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Esto creará nuestra animación y hará desaparecer el form. Igualmente escribirá los datos JSON a la &lt;div&gt; que hemos especificado.</p>
<p><strong>Puedes descargar los archivos de este ejemplo funcionando aquí: <a href="http://blog.ipalaus.es/dm.php?id=4">ipalaus-ajaxlogin-v0.2.rar</a></strong>.</p>
<p>¡Gracias a todos! ¡Espero que funcione!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ipalaus.es/ajax-login-con-jquery-y-codeigniter-v2-archivos/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>AJAX Login con jQuery y Code Igniter (PHP)</title>
		<link>http://blog.ipalaus.es/ajax-login-con-jquery-y-code-igniter-php</link>
		<comments>http://blog.ipalaus.es/ajax-login-con-jquery-y-code-igniter-php#comments</comments>
		<pubDate>Fri, 07 Mar 2008 22:23:37 +0000</pubDate>
		<dc:creator>Isern Palaus</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ajax login]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ipalaus.es/?p=1</guid>
		<description><![CDATA[Nueva versión del tutorial: AJAX Login con jQuery y CodeIgniter – v2 + archivos
Uno de los principales problemas a la hora de empezar a programar es que muchos usuarios necesitamos donde mirar por tal de tener una base para empezar nuestro programa. No es lo mejor a la larga porque siempre terminamos basando nuestro trabajo <a href="http://blog.ipalaus.es/ajax-login-con-jquery-y-code-igniter-php" class="more-link">Más &#62;</a>]]></description>
			<content:encoded><![CDATA[<p><strong>Nueva versión del tutorial: <a href="http://blog.ipalaus.es/ajax-login-con-jquery-y-codeigniter-v2-archivos">AJAX Login con jQuery y CodeIgniter – v2 + archivos</a></strong></p>
<p>Uno de los principales problemas a la hora de empezar a programar es que muchos usuarios necesitamos donde mirar por tal de tener una base para empezar nuestro programa. No es lo mejor a la larga porque siempre terminamos basando nuestro trabajo en otros proyectos, pero es una buena forma de empezar a programar. En este caso explicaré como hacer un sistema que valide a lo usuarios mediante un formulario AJAX y el <em>framework</em> PHP <a href="http://www.codeigniter.com">Code Igniter</a>.</p>
<p>Lo primero que necesitamos en este caso es jQuery que podemos descargarlo desde <a href="http://www.jquery.com">la web oficial</a>. jQuery es una librería de JavaScript que nos facilita muchísimo las cosas a la hora de programar. Obviamente también necesitaremos Code Igniter y me reservo el derecho en publicar una entrada futura sobre el mismo.</p>
<p>Para empezar lo haremos con una cosa sencilla, la base de datos que vamos a usar. Es bien simple: id, usuario, contraseña, correo y hora de &#8220;registro&#8221;.</p>
<p>[code lang="mysql"]<br />
CREATE TABLE `users` (<br />
`uid` int(10) NOT NULL auto_increment,<br />
`username` varchar(16) NOT NULL,<br />
`password` varchar(32) NOT NULL,<br />
`email` varchar(128) NOT NULL,<br />
`time` int(10) NOT NULL,<br />
PRIMARY KEY (`uid`)<br />
) ENGINE=InnoDB DEFAULT CHARSET=latin1;</p>
<p>[/code]</p>
<p>Ahora es hora del controlador que llamaré <strong>user.php</strong>, este user.php se ocupará de las funciones básicas como son: comprobar el usuario y la desconexión del mismo.</p>
<p>[code lang="php"]<br />
load-&gt;model("user_model");<br />
$this-&gt;load-&gt;model("dalia_model");</p>
<p>$this-&gt;load-&gt;helper("security");<br />
$this-&gt;load-&gt;helper("form");<br />
}</p>
<p>/* Checks if the password that the user gives is equal at the DB ones */<br />
function _check_login($username) {<br />
$password = md5($this-&gt;validation-&gt;password);</p>
<p>if(!$this-&gt;user_model-&gt;checkUserLogin($username,$password,"users"))<br />
return FALSE;</p>
<p>return TRUE;<br />
}</p>
<p>function index() {<br />
$this-&gt;load-&gt;view("userLogin");<br />
}</p>
<p>function checkLogin()<br />
{<br />
$this-&gt;load-&gt;library('validation');<br />
$rules['username'] = 'trim|required|callback__check_login';<br />
$rules['password'] = 'trim|required';<br />
$this-&gt;validation-&gt;set_rules($rules);</p>
<p>$fields['username'] = 'username';<br />
$fields['password'] = 'password';<br />
$this-&gt;validation-&gt;set_fields($fields);</p>
<p>if ($this-&gt;validation-&gt;run()) {<br />
$username     = $this-&gt;validation-&gt;username;<br />
$uid         = $this-&gt;user_model-&gt;getUserId($username,"users");</p>
<p>$this-&gt;session-&gt;set_userdata("logged_in",$uid);</p>
<p>$output = '{ "success": "yes", "welcome": "Welcome" }';<br />
} else {<br />
$output = '{ "success": "no", "message": "This is not working" }';<br />
}</p>
<p>$output = str_replace("\r", "", $output);<br />
$output = str_replace("\n", "", $output);</p>
<p>echo $output;<br />
}</p>
<p>function logout()<br />
{<br />
$this-&gt;session-&gt;sess_destroy();<br />
redirect("");<br />
}</p>
<p>}</p>
<p>?&gt;<br />
[/code]</p>
<p>Para el login en AJAX vamos a tener que usar una comprobación en PHP que la llamaremos mediante jQuery. Es tan simple como saber si el usuario que intentamos acceder es válido o no lo es. Esta función de comprobar el usuario es checkLogin() y la analizamos desde el principio. En primer termino nos encontramos con:</p>
<p>[code lang="php"]<br />
$rules['username'] = 'trim|required|callback__check_login';<br />
[/code]</p>
<p>Que hace una llamada a la función _check_login(). Es la función que realmente comprueba en al base de datos si el usuario existe o no en la misma:</p>
<p>[code lang="php"]<br />
function _check_login($username) {<br />
$password = md5($this-&gt;validation-&gt;password);</p>
<p>if(!$this-&gt;user_model-&gt;checkUserLogin($username,$password,"users"))<br />
return FALSE;</p>
<p>return TRUE;<br />
}<br />
[/code]</p>
<p>Lo primero que hacemos es obtener la contraseña y codificarla en md5, ya que es como reside en la base de datos. Mediante el modelo <em>user_model</em>, que analizaremos más adelante, comprobamos con el nombre de usuario y contraseña que el usuario ha ingresado si coinciden con los que corresponden. Si esto es verdad, y coinciden, devolveremos un <em>TRUE</em>&#8230; del contrario, <em>FALSE</em>.</p>
<p>El modelo que usamos para comprobar el usuario, llamado <strong>user_model.php</strong>, es muy sencillo. El código es el siguiente:</p>
<p>[code lang="php"]<br />
db-&gt;where("username",$username);<br />
$query = $this-&gt;db-&gt;where("password",$password);<br />
$query = $this-&gt;db-&gt;limit(1,0);<br />
$query = $this-&gt;db-&gt;get($table);</p>
<p>if ($query-&gt;num_rows() == 0) {<br />
return NULL;<br />
}</p>
<p>return TRUE;<br />
}<br />
}<br />
?&gt;<br />
[/code]</p>
<p>Simplemente devuelve <em>TRUE</em> o <em>FALSE</em> dependiendo de si son válidos los datos que pasamos a la función.</p>
<p>Una vez tenemos casi todo el código, es hora de la <em>View</em> donde mostraremos el formulario en AJAX. Tengo las vistas separadas de modo que pueda cargar un <em>header</em>, el contenido y un <em>footer</em>. Mi formulario irá al <em>header</em> pero podría funcionar en cualquier otro sitio.</p>
<p>[code lang="php"]</p>
<p><!-- Extra Head Content --></p>
<p><!-- Extra Head Content --></p>
<div id="content">
<div id="header">
<div id="logo"><img src="&lt;?=base_url();?&gt;content/img/logo.png" alt=" " width="321px" height="111px" /></div>
<div id="login">session-&gt;userdata('logged_in')) {<br />
?&gt;</p>
<div id="logged">Welcome, you're already logged In.</div>
<div id="loginform">'userlogin'));?&gt;<br />
<label for="username">Username:</label></p>
<input id="username" class="logininput" name="username" type="text" />
<label for="password">Password:</label></p>
<input id="password" class="logininput" name="password" type="password" />
<input class="loginsubmit" type="submit" value="Login" /></div>
</div>
</div>
<div id="body">[/code]</p>
<p>Como comprobaciones en medio de la vista nos podemos dar cuenta de la siguiente:</p>
<p>[code lang="php"]<br />
if($this-&gt;session-&gt;userdata('logged_in')) {<br />
[/code]</p>
<p>Simplemente lo usamos para comprobar si es un usuario que ya ha logeado o si es un nuevo usuario. Si es nuevo, esta comprobación fallará y nos mostrará el nuevo formulario de login. No tiene ningún tipo de complicación. Lo que más puede generar dudas es el código de jQuery, que también es muy simple y son pocas lineas:</p>
<p>[code lang="javascript"]<br />
$(document).ready(<br />
function(){</p>
<p>$("#userlogin").ajaxForm({<br />
type: "POST",<br />
url: "/user/checkLogin",<br />
dataType: "json",<br />
data: "username="+$("#username").val()+"&amp;password;="+$("#password").val(),<br />
success: updateLogin<br />
});</p>
<p>}<br />
)<br />
[/code]</p>
<p>Para usar este tipo de llamada (ajaxForm) vamos a necesitar el plugin jQuery Form que podemos descargar desde la <a href="http://www.malsup.com/jquery/form/">página del autor</a>. Como curiosidad destacar el <em>success: updateLogin</em> que se encargará de actualizar nuestro formulario sin necesidad de cargar de nuevo la página. Esta es otra función a parte que llama una vez ha ejecutado el <em>script</em>. El código es el siguiente:</p>
<p>[code lang="javascript"]<br />
function updateLogin(data) {<br />
$('#logged').html('');<br />
$('#logged').hide();</p>
<p>$("#loginform").fadeOut("slow",<br />
function() {<br />
if (data.success == 'yes') {<br />
$('#logged').html(data.welcome).fadeIn("slow");<br />
}</p>
<p>if (data.success == 'no') {<br />
$('#loginerror').html(data.message).fadeIn("slow").fadeOut("slow",<br />
function() {<br />
$("#loginform").fadeIn("slow");<br />
}<br />
);<br />
}<br />
}<br />
);</p>
<p>}<br />
[/code]</p>
<p>Dependiendo de si el script PHP ha devuelto <em>success == yes</em> o <em>success == no</em>, ejecutará y actualizará de un modo o de otro. Los <em>data.welcome</em> o <em>data.message</em> son los mensajes que hemos enviado usando JSON a la hora de validar el script en el controlador <em>user.php</em>.</p>
<p>Bien, espero que con esto puedan crear su primer login en AJAX usando jQuery y PHP. Pronto, más sobre AJAX, PHP y CodeIgniter!</p></div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.ipalaus.es/ajax-login-con-jquery-y-code-igniter-php/feed</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
	</channel>
</rss>
