<?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"
	>

<channel>
	<title>Blog cakephp en español por Hospedaxes</title>
	<atom:link href="http://cakephp.hospedaxes.com/feed" rel="self" type="application/rss+xml" />
	<link>http://cakephp.hospedaxes.com</link>
	<description>Blog sobre desarrollo web con cakephp en español por Hospedaxes</description>
	<pubDate>Fri, 08 Aug 2008 06:39:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Autocompletar ajax</title>
		<link>http://cakephp.hospedaxes.com/autocompletar-ajax</link>
		<comments>http://cakephp.hospedaxes.com/autocompletar-ajax#comments</comments>
		<pubDate>Thu, 07 Aug 2008 10:20:32 +0000</pubDate>
		<dc:creator>bernal</dc:creator>
		
		<category><![CDATA[ajax]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=10</guid>
		<description><![CDATA[En la entrada semanal de nuestro blog relacionado con cakephp, vamos a hablar sobre autocompletar los campos mediante ajax, una opción que puede simplificar bastante la inserción de datos por parte de los usuarios y que a su vez resulta bastante elegante.
El funcionamiento es sencillo, al introducir una letra en un campo de entrada se [...]]]></description>
			<content:encoded><![CDATA[<p>En la entrada semanal de nuestro blog relacionado con <a href="http://cakephp.hospedaxes.com/">cakephp</a>, vamos a hablar sobre autocompletar los campos mediante ajax, una opción que puede simplificar bastante la inserción de datos por parte de los usuarios y que a su vez resulta bastante elegante.</p>
<p>El funcionamiento es sencillo, al introducir una letra en un campo de entrada se buscarán en la base de datos las coincidencias con el texto que hemos insertado, mostrándolas como una lista y dándonos la opción de elegir entre todos los resultados.</p>
<p>Esta opción se usa habitualmente con los listados de paises, en nuestro ejemplo utilizaremos, como en el ejemplo de <a href="http://cakephp.hospedaxes.com/actualizar-el-contenido-de-un-select-con-ajax">actualizar un select con ajax</a>, las provincias españolas.</p>
<p>En <a href="http://cakephp.hospedaxes.com/pruebas/ejemplo_complete" target="_blank">este enlace</a> se puede comprobar el funcionamiento.</p>
<p>Añadirlo en nuestro proyecto es realmente sencillo, supongamos que tenemos un modelo, cuyo controlador tiene una operación y una vista asociada, que será donde queremos utilizarlo.</p>
<p>Para ello en la vista, añadimos este trozo de código dentro de un formulario:</p>
<pre class="prettyprint">
 echo $form->label('provincias','Provincias');
 echo $ajax->autoComplete('nombre','autocomplete');
</pre>
<p>Añadimos un label que tendrá el texto Provincias y un campo de entrada autocomplete, este recibe como parámetros, el nombre del campo y como segundo parámetro la url donde se encuentra la función a la que se va a llamar cuando se introduzca una letra, en nuestro caso, la vamos a añadir en el mismo controlador que estamos utilizando, si no fuese así la dirección sería &#8216;/nombre_del_controlador/función&#8217;.</p>
<p>En segundo lugar, creamos la función autocomplete, dentro del controlador utilizado añadimos el siguiente código:</p>
<pre class="prettyprint">
  function autocomplete()
  {
 	$str = trim($this->data['Provincia']['nombre']);
	$str = str_replace("á","a",$str);
	$str = str_replace("é","e",$str);
	$str = str_replace("í","i",$str);
	$str = str_replace("ó","o",$str);
	$str = str_replace("ú","u",$str);
	$str = str_replace("Á","A",$str);
	$str = str_replace("É","E",$str);
	$str = str_replace("Í","I",$str);
	$str = str_replace("Ó","O",$str);
	$str = str_replace("Ú","U",$str);
	$str = str_replace("Ñ","ñ",$str);
	$condicion = "REPLACE (REPLACE( REPLACE( REPLACE( REPLACE( REPLACE ( Provincia.nombre,'á','a'), 'é','e'),'í','i'),'ó','o'),'ú','u'),'Ñ','ñ') LIKE "$str%"";
	$this->set('provincias', Set::combine($this->Provincia->findAll($condicion,array('Provincia.nombre','Provincia.id'),'Provincia.nombre'), "{n}.Provincia.id","{n}.Provincia.nombre"));
	$this->render('autocomplete','ajax');
 }
</pre>
<p>La función es muy sencilla, realiza la búsqueda en la base de datos de todas las provincias cuyo nombre coincida con el texto introducido, pasado en $this->data con el nombre que se indica en el primer parámetro de la función autocomplete utilizada en la vista, para eso se añade en la condición la opción LIKE cadena% de sql.</p>
<p>Todas las opciones que añadimos anteriormente sirven para ignorar los acentos, tanto en la cadena que introducimos como en los nombres de las provincias almacenadas en la base de datos, con esto al realizar la búsqueda funcionará aunque cometamos fallos ortográficos.</p>
<p>Crearemos una vista para esta función, con una única línea de código, que crea una lista con todas las entradas del array.</p>
<pre class="prettyprint">
 echo $html->nestedList($provincias);
</pre>
<p>Y por último añadiremos al css que estemos utilizando, dos clases que modificarán el aspecto del listado que hemos creado:</p>
<pre class="prettyprint">
  div.auto_complete {
 	position :absolute;
 	width :250px;
 	background-color :white;
 	border :1px solid #888;
 	margin :0px;
 	padding :0px;
  }

 div.auto_complete ul{
	list-style: none;
	margin: 0px;
 }

 li.selected{
	background-color: #ffb;
 }
</pre>
<p>Con esto ya tendremos un campo de texto en el que al añadir texto se generará un listado con todas las entradas de la base de datos que coincidan con el texto introducido.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/autocompletar-ajax/feed</wfw:commentRss>
		</item>
		<item>
		<title>Calendario en CakePHP 1.2</title>
		<link>http://cakephp.hospedaxes.com/calendario-en-cakephp-12</link>
		<comments>http://cakephp.hospedaxes.com/calendario-en-cakephp-12#comments</comments>
		<pubDate>Mon, 28 Jul 2008 12:20:04 +0000</pubDate>
		<dc:creator>nuria</dc:creator>
		
		<category><![CDATA[Noticias]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<category><![CDATA[cakephp]]></category>

		<category><![CDATA[calendario]]></category>

		<category><![CDATA[helper]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=12</guid>
		<description><![CDATA[Cuando estamos desarrollando una página web, a menudo necesitamos introducir un calendario que nos permita seleccionar las fechas sin tener que escribirlas a mano.
En este post vamos a explicar cómo hacer esto, utilizando para ello el calendario DHTML Calendar desarrollado por Dynarch. Es un calendario con licencia GNU y que cubre perfectamente todas las funcionalidades [...]]]></description>
			<content:encoded><![CDATA[<p>Cuando estamos <a href="http://www.hospedaxes.com">desarrollando una página web</a>, a menudo necesitamos introducir un calendario que nos permita seleccionar las fechas sin tener que escribirlas a mano.</p>
<p>En este post vamos a explicar cómo hacer esto, utilizando para ello el calendario <a href="http://www.dynarch.com/projects/calendar/">DHTML Calendar</a> desarrollado por <a href="http://www.dynarch.com/">Dynarch</a>. Es un calendario con licencia <a href="http://es.wikipedia.org/wiki/Licencia_p%C3%BAblica_general_de_GNU">GNU</a> y que cubre perfectamente todas las funcionalidades que necesitamos.</p>
<p>Todos los ficheros necesarios para introducir el calendario en nuestra página web, junto con la estructura como se organizan en CakePHP 1.2, pueden descargarse <a href="http://cakephp.hospedaxes.com/wp-content/uploads/2008/07/calendariotar.gz">calendario</a>. Lo explicaremos paso a paso.</p>
<p>Lo primero que tenemos que hacer es descargarnos el calendario (podemos hacerlo directamente de la página web de Dynarch, o bien mediante el enlace del párrafo anterior) y descomprimirlo en la carpeta <em>app/webroot/js</em>. Necesitamos también otro fichero javascript, <em>common.js</em>, que también meteremos en esa carpeta. En el <em>body</em>, incluiremos estos ficheros escribiendo:</p>
<pre class="prettyprint">// Calendar includes
echo $javascript->link('jscalendar-1.0/calendar.js');
echo $javascript->link('jscalendar-1.0/lang/calendar-es.js');
echo $javascript->link('common.js');
// CSS Theme
echo $html->css('../js/jscalendar-1.0/skins/aqua/theme');</pre>
<p>Necesitamos ahora implementar un helper para que nos sea mucho más fácil la utilización de este calendario. Lo descargamos del enlace anterior y lo metemos en la carpeta <em>app/views/helpers</em>. Si miramos el código de este helper vemos que tenemos dos funciones, <strong>picker</strong> y <strong>flat</strong>, que nos permiten hacer que este calendario aparezca al pulsar un botón o que esté siempre visible en nuestra página.</p>
<p>Ya sólo nos falta introducir este calendario en nuestras páginas.</p>
<p>En el controlador, importamos el helper:</p>
<pre class="prettyprint">var $helpers = array('DatePicker');</pre>
<p>Y en la vista mostramos el calendario:</p>
<pre class="prettyprint">echo $datePicker->flat('fechaCalendarioFlat', array('id'=>'fechaCalendarioFlat'));
echo $datePicker->picker('fechaCalendarioPicker', array('id'=>'fechaCalendarioPicker'));</pre>
<p>Podemos ver una demostración del funcionamiento del calendario en este <a title="Calendario en CakePHP 1.2" href="http://cakephp.hospedaxes.com/pruebas/calendario">enlace</a>.</p>
<p>A partir del código proporcionado, podríamos añadir muchas funcionalidades. Por ejemplo, podremos editar el código del helper, para añadirle un observador de javascript al calendario tipo flat y que al pulsar en una fecha nos lleve a otra url, o podríamos hacer que ciertas fechas especiales se coloreen de manera distinta al resto.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/calendario-en-cakephp-12/feed</wfw:commentRss>
		</item>
		<item>
		<title>Múltiples conexiones a bases de datos</title>
		<link>http://cakephp.hospedaxes.com/multiples-conexiones-a-bases-de-datos</link>
		<comments>http://cakephp.hospedaxes.com/multiples-conexiones-a-bases-de-datos#comments</comments>
		<pubDate>Tue, 22 Jul 2008 11:04:19 +0000</pubDate>
		<dc:creator>bernal</dc:creator>
		
		<category><![CDATA[cakephp-1.2]]></category>

		<category><![CDATA[bases de datos]]></category>

		<category><![CDATA[multiples bases de datos]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=19</guid>
		<description><![CDATA[En cakephp existen gran cantidad de posibilidades desconocidas que, en algunos casos, pueden resultar útiles.
Una de ellas es la posibilidad de declarar más de una conexión a base de datos, pudiendo elegir en cada momento cuál de ellas deseamos utilizar.
Puede resultar muy cómodo para organizar nuestros proyectos, para acceder a diferentes servidores de bases de [...]]]></description>
			<content:encoded><![CDATA[<p>En cakephp existen gran cantidad de posibilidades desconocidas que, en algunos casos, pueden resultar útiles.<br />
Una de ellas es la posibilidad de declarar más de una conexión a base de datos, pudiendo elegir en cada momento cuál de ellas deseamos utilizar.</p>
<p>Puede resultar muy cómodo para organizar nuestros proyectos, para acceder a diferentes servidores de bases de datos o acceder a diferentes gestores de bases de datos.</p>
<p>El proceso es sencillo, en primer lugar añadiremos al archivo database.php situado en /app/config/ una nueva configuración de base de datos.<br />
Podremos copiar la configuración por defecto, llamada default, y cambiarle el nombre.<br />
El fichero database.php quedará así</p>
<pre class="prettyprint">class DATABASE_CONFIG {

	var $default = array(
		'driver' => 'mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'user',
		'password' => 'password',
		'database' => 'database',
		'prefix' => '',
	);

	var $nueva_conexion = array(
		'driver' => 'mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'user',
		'password' => 'password',
		'database' => 'database_2',
		'prefix' => '',
	);

	var $test = array(
		'driver' => 'mysql',
		'persistent' => false,
		'host' => 'localhost',
		'login' => 'user',
		'password' => 'password',
		'database' => 'test_database_name',
		'prefix' => '',
	);
}</pre>
<p>Con esto habremos declarado otra conexión a la base de datos llamada nueva_conexion.<br />
Una de las opciones que tiene la configuración de la base de datos, es la de utilizar un prefijo, es decir, que todas las tablas de la configuración de la base de datos comiencen con una palabra, también puede ser utilizado para organizar las bases de datos.</p>
<p>Para utilizar la configuración de la base de datos que hemos creado, tendremos que añadir en el modelo desde donde queremos acceder a esas tablas la siguiente línea:</p>
<pre class="prettyprint">	var $useDbConfig ='nueva_conexion';</pre>
<p>A partir de este momento, cada vez que accedamos a este modelo, cakephp utilizará las tablas existentes en la base de datos de esa conexión.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/multiples-conexiones-a-bases-de-datos/feed</wfw:commentRss>
		</item>
		<item>
		<title>Localización e internacionalización</title>
		<link>http://cakephp.hospedaxes.com/localizacion-e-internacionalizacion</link>
		<comments>http://cakephp.hospedaxes.com/localizacion-e-internacionalizacion#comments</comments>
		<pubDate>Wed, 16 Jul 2008 08:20:50 +0000</pubDate>
		<dc:creator>nuria</dc:creator>
		
		<category><![CDATA[Noticias]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=17</guid>
		<description><![CDATA[Vamos a ver cómo realizar la internacionalización de nuestra página web. Nos fijaremos únicamente en hacer nuestra página web en varios idiomas, sin atender a otras cuestiones como puede ser el formateo de las monedas o los números.
Los pasos a realizar son los siguientes:
1. Crear tantos ficheros de idiomas como queramos tener. Estos ficheros los [...]]]></description>
			<content:encoded><![CDATA[<p>Vamos a ver cómo realizar la <a title="Internationalization and localization" href="http://en.wikipedia.org/wiki/Internationalization_and_localization">internacionalización </a>de nuestra página web. Nos fijaremos únicamente en hacer nuestra página web en varios idiomas, sin atender a otras cuestiones como puede ser el formateo de las monedas o los números.</p>
<p>Los pasos a realizar son los siguientes:</p>
<p><strong>1. </strong>Crear tantos ficheros de idiomas como queramos tener. Estos ficheros los meteremos en la carpeta <em>/app/locale</em>, creando una carpeta por cada idioma que tendrá por nombre el código de 3 letras del lenguaje (ISO 639-2, <a href="http://www.loc.gov/standards/iso639-2/php/code_list.php">lista de lenguajes</a>). Y dentro de esta carpeta, crearemos otro subdirectorio llamado<em> LC_MESSAGES</em> y por último, en éste, un fichero <em>default.po</em>.</p>
<p>Ejemplo para castellano y gallego:</p>
<p style="text-align: center;"><a href="http://www.hospedaxes.com/blog-cakephp/wp-content/uploads/2008/07/jerarquia.png"><img class="alignnone size-medium wp-image-21" title="jerarquia" src="http://www.hospedaxes.com/blog-cakephp/wp-content/uploads/2008/07/jerarquia.png" alt="Jerarquia" width="214" height="157" /></a></p>
<p>Este fichero debe estar codificado en <span>ISO-8859-1 y los strings no pueden tener más de 1014 caracteres. Se asocian las claves con los valores de la siguiente manera: </span></p>
<p style="text-align: center;">msgid &#8220;clave&#8221;<br />
msgstr &#8220;valor&#8221;</p>
<p>Teniendo en cuenta que cada clave debe ser única.</p>
<p><strong>2. </strong>Modificar el <em>app_controller</em> para establecer el lenguaje elegido.</p>
<pre class="prettyprint">uses('L10n');
class AppController extends Controller
{
   function beforeFilter() {
      $this->L10n = new L10n();
      $languages = array('es', 'gl');
      $paramLang = $this->params['plugin'];
      $lang = $this->Session->check('lang') ? $this->Session->read('lang'): 'es';
      if (isset($paramLang) &amp;&amp; in_array($paramLang, $languages)) {
         $lang = $paramLang;
      }

      $this->Session->write('lang', $lang);
      $this->L10n->get($lang);
      Configure::write('Config.language', $lang);
   }
}</pre>
<p>Lo que hacemos aquí es recoger el valor de la url, si existe, y si no obtenerlo de la sesión.</p>
<p>Recordar que el parámetro <em>plugin</em> de la url es el que se establece justo antes del nombre del controlador, por lo tanto las urls serán de la forma:</p>
<p style="text-align: center;">www.hospedaxes.com/es/controlador/accion/&#8230;<br />
www.hospedaxes.com/gl/controlador/accion/&#8230;</p>
<p><strong>3.</strong> Para usar los valores establecidos en los ficheros .po, tenemos que utilizar la función <strong>__()</strong>, al que se le pasa la clave y un booleano opcional [false si queremos que se comporte como un echo (valor por defecto), true para que devuelva únicamente una cadena].</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/localizacion-e-internacionalizacion/feed</wfw:commentRss>
		</item>
		<item>
		<title>Nueva versión de cakephp 1.2</title>
		<link>http://cakephp.hospedaxes.com/nueva-version-de-cakephp-12</link>
		<comments>http://cakephp.hospedaxes.com/nueva-version-de-cakephp-12#comments</comments>
		<pubDate>Thu, 03 Jul 2008 12:12:34 +0000</pubDate>
		<dc:creator>bernal</dc:creator>
		
		<category><![CDATA[Noticias]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=20</guid>
		<description><![CDATA[Cada vez estamos más cerca de la versión final del framework al que dedicamos este blog.
Desde la página de cakephp se puede descargar la versión 1.2.0.7296 rc2, nueva candidata que hace que el lanzamiento de la versión definitiva se encuentre más cercano.
Como en cada actualización, corrección de bugs y pequeñas mejoras que se pueden ver [...]]]></description>
			<content:encoded><![CDATA[<p>Cada vez estamos más cerca de la versión final del framework al que dedicamos este blog.</p>
<p>Desde la página de <a href="http://www.cakephp.org" target="_blank">cakephp</a> se puede descargar la versión 1.2.0.7296 rc2, nueva candidata que hace que el lanzamiento de la versión definitiva se encuentre más cercano.</p>
<p>Como en cada actualización, corrección de bugs y pequeñas mejoras que se pueden ver en el siguiente <a href="https://trac.cakephp.org/wiki/changelog/1.2.x.x" target="_blank">enlace</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/nueva-version-de-cakephp-12/feed</wfw:commentRss>
		</item>
		<item>
		<title>Actualizar el contenido de un select con ajax.</title>
		<link>http://cakephp.hospedaxes.com/actualizar-el-contenido-de-un-select-con-ajax</link>
		<comments>http://cakephp.hospedaxes.com/actualizar-el-contenido-de-un-select-con-ajax#comments</comments>
		<pubDate>Wed, 11 Jun 2008 07:44:11 +0000</pubDate>
		<dc:creator>bernal</dc:creator>
		
		<category><![CDATA[ajax]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<category><![CDATA[actualizar selects]]></category>

		<category><![CDATA[cakephp]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=5</guid>
		<description><![CDATA[En esta entrada vamos a explicar como asociar dos selects mediante ajax y al modificar el elemento seleccionado en uno de ellos  cambie el contenido del otro.
Podemos ver el ejemplo de funcionamiento aquí.
Un ejemplo muy claro para esta situación sería dos selects, uno con provincias y el otro con localidades, lo que queremos es [...]]]></description>
			<content:encoded><![CDATA[<p>En esta entrada vamos a explicar como asociar dos selects mediante ajax y al modificar el elemento seleccionado en uno de ellos  cambie el contenido del otro.</p>
<p>Podemos ver el ejemplo de funcionamiento <a href="http://www.hospedaxes.com/blog-cakephp/pruebas" target="_blank">aquí.</a></p>
<p>Un ejemplo muy claro para esta situación sería dos selects, uno con provincias y el otro con localidades, lo que queremos es que al cambiar de provincia varíe la lista de localidades y muestre las que están en la provincia seleccionada.</p>
<p>Lo haremos utilizando el ajaxHelper, para que no sea necesario la recarga de la página y quede más atractivo.</p>
<p>Lo primero que haremos será definir los modelos de provincias ,localidades y un tercer modelo en el que usaremos los selects, por ejemplo podría ser un modelo de cliente, en el que al insertar un nuevo cliente tendríamos que elegir la provincia y localidad a la que pertenece.</p>
<h1><span style="text-decoration: underline;">Modelos</span></h1>
<p><strong>Modelo de provincia.</strong></p>
<pre class="prettyprint">/app/models/provincia.php

class Provincia extends AppModel
{
    var $name = 'Provincia';
}</pre>
<p><strong>Modelo de localidad.</strong></p>
<pre class="prettyprint">/app/models/localidade.php

class Localidade extends AppModel
{
    var $name = 'localidade';
}</pre>
<p><strong>Modelo de cliente.</strong></p>
<pre class="prettyprint">/app/models/cliente.php

class Cliente extends AppModel
{
    var $name = 'Cliente';
}</pre>
<h1><span style="text-decoration: underline;">Controladores</span></h1>
<p>Después de esto tendremos que definir los controladores.</p>
<p><strong>Controlador de localidad.</strong></p>
<pre class="prettyprint">/app/controllers/localidades_controller.php

class LocalidadesController extends AppController
{
	var $name = 'Localidades';
}</pre>
<p><strong>Controlador de provincia.</strong></p>
<pre class="prettyprint">/app/controllers/provincias_controller.php

class ProvinciasController extends AppController
{
	var $name = 'Provincias';
}</pre>
<p>Y por últino el controlador de clientes que será el que implementará la funcionalidad.</p>
<p><strong>Controlador de cliente.</strong></p>
<pre class="prettyprint">/app/controllers/clientes_controller.php

class ClientesController extends AppController
{
	var $name = 'Clientes';
	var $helpers = array('Ajax');
	var $uses = array('Cliente','Provincia','Localidade');

	function insertar()
	{
		$listadoProvincias = $this->Provincia->find('all', array('fields'=>array('id','nombre'),'order'=>'nombre ASC'));
		$this->set('provincias', Set::combine($listadoProvincias, "{n}.Provincia.id","{n}.Provincia.nombre"));
		$primera_provincia = $this->Provincia->find(null,null,'nombre ASC');
		$listadoLocalidades = $this->Localidade->find('all', array('fields'=>array('id','nombre'),'order'=>'nombre ASC','conditions'=>'Localidade.provincia_id='.$primera_provincia['Provincia']['id']));
		$this->set('localidades', Set::combine($listadoLocalidades, "{n}.Localidade.id","{n}.Localidade.nombre"));

		// RESTO DE LA FUNCIONALIDAD DE INSERCIÓN DE CLIENTES
	}

	function update_select()
	{
		if (!empty($this->data['Localidade']['provincia_id']))
		{
			$provincia_id = $this->data['Localidade']['provincia_id'];
			$localidades = $this->Localidade->find('all', array('fields'=>array('id','nombre'),'order'=>'nombre ASC','conditions'=>array('provincia_id'=>$provincia_id)));
		}
		else
		{
			$localidades = $this->Localidade->find('all', array('fields'=>array('id','nombre'),'order'=>'nombre ASC'));
		}
		$this->set('options', Set::combine($localidades, "{n}.Localidade.id","{n}.Localidade.nombre"));
		$this->render('/elements/update_select', 'ajax');
	}
}</pre>
<p>Por un lado tenemos la <strong>función insertar</strong>, que será una función genérica de inserción de clientes. La parte que a nosotros nos interesa es en la que se inicializan las variables que después utilizaremos en los selects, estas deberán ser arrays en los que cada elemento tenda un identificador y su valor, para que el select pueda utilizarlos en la vista.</p>
<p>En la versión 1.1 de cakephp, esto se podía hacer mediante la función generateList del modelo, función que se ha eliminado en la 1.2.<br />
Por ello ahora es necesario hacerlo en dos pasos, por un lado realizar la búsqueda con un findAll y después utilizar la función combine de la clase Set que genera un array con la estructura deseada, que será el que le pasemos a la vista.</p>
<pre class="prettyprint">$listadoProvincias = $this->Provincia->find('all', array('fields'=>array('id','nombre'),'order'=>'nombre ASC'));
$this->set('provincias', Set::combine($listadoProvincias, "{n}.Provincia.id","{n}.Provincia.nombre"));</pre>
<p>La segunda función <strong>update_select</strong>, es a la que llamará el ajax para actualizar el listado de localidades a partir de un identificador de provincia.</p>
<p>Como se puede ver en el código, la función coge el identificador de provincia del select y envía a la vista los arrays actualizados de provincias y localidades.</p>
<h1><span style="text-decoration: underline;">Vistas</span></h1>
<p>Localidades y provincias no tendrán vistas asociadas, ya que no hay ninguna operación en el controlador.</p>
<p>En clientes tendremos que crear la vista para la operación insertar del controlador, esta podría ser algo como esto:</p>
<pre class="prettyprint">/app/views/clientes/insertar.ctp

echo $form->create('Inscripcione',array('action'=>'insertar'));
echo $form->inputs(array('legend'=>'Actualizar Provincias',
		'Localidade.provincia_id' => array('label'=> 'Provincia','showEmpty'=>'false','id'=>'provincias'),
		'Alumno.localidade_id' => array('label'=> 'Localidad','showEmpty'=>'false','id'=>'localidades'),
			));
echo $form->end();

$options = array('url' => 'update_select','update' => 'localidades');
echo $ajax->observeField('provincias',$options);</pre>
<p>La vista será muy sencilla, un formulario con dos selects, uno de localidades y otro de provincias y una llamada al ajaxHelper en la que se indica que cada vez que se modifique el valor del select provincias, se llame a la función update_select y actualice el select de localidades.</p>
<p>Este select se actualizará con los valores devueltos por la vista de update_select, que lo único que hace es imprimir todos los nombres de localidades devueltos por la función del controlador.</p>
<pre class="prettyprint">/app/views/elements/update_select.ctp
if(!empty($options)) {
  foreach($options as $k => $v) {
    echo <code >"&lt;option value='$k'&gt;$v&lt;/option&gt;";</code>
  }
 }
</pre>
<p>En este enlace se puede ver un ejemplo de <a href="http://www.hospedaxes.com/blog-cakephp/pruebas" target="_blank">funcionamiento</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/actualizar-el-contenido-de-un-select-con-ajax/feed</wfw:commentRss>
		</item>
		<item>
		<title>Nueva versión de cakephp disponible.</title>
		<link>http://cakephp.hospedaxes.com/nueva-version-de-cakephp-disponible</link>
		<comments>http://cakephp.hospedaxes.com/nueva-version-de-cakephp-disponible#comments</comments>
		<pubDate>Tue, 10 Jun 2008 10:16:40 +0000</pubDate>
		<dc:creator>bernal</dc:creator>
		
		<category><![CDATA[Noticias]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<category><![CDATA[cakephp]]></category>

		<category><![CDATA[candidata]]></category>

		<category><![CDATA[framework]]></category>

		<category><![CDATA[hospedaxes]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=18</guid>
		<description><![CDATA[
Desde hace unos días está disponible en la página de cakephp, una nueva versión, la 1.2.0.7125 RC1, de este framework de desarrollo escrito en php, del que hablamos en nuestro blog y en el que desarrollamos la gran mayoría de las webs que se crean en nuestra empresa.
Lo importante de esta noticia es que el [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cakeforge.org/frs/?group_id=23&amp;release_id=395" target="_blank"><img class="alignleft" style="float: left; margin-left: 12px; margin-right: 12px;" src="http://cakephp.org/img/new.png" alt="" width="230" height="225" /></a></p>
<p>Desde hace unos días está disponible en la página de <a title="cakephp" href="http://cakephp.org" target="_blank">cakephp</a>, una nueva versión, la <a href="http://cakeforge.org/frs/?group_id=23&amp;release_id=395" target="_blank">1.2.0.7125</a> RC1, de este framework de desarrollo escrito en php, del que hablamos en nuestro blog y en el que desarrollamos la gran mayoría de las <a href="http://www.hospedaxes.com" target="_blank">webs</a> que se crean en nuestra empresa.</p>
<p>Lo importante de esta noticia es que el framework ha abandonado la categoría de beta, pasando a ser una versión candidata, cada vez está más cerca el lanzamiento de la versión final.</p>
<p>En esta versión se eliminan gran cantidad de métodos <a href="https://trac.cakephp.org/changeset/4981" target="_blank">deprecados</a> y se corrigen multitud de errores.</p>
<p>A partir de ahora siempre que hablemos de funcionalidades del cakephp 1.2 nos referiremos a la versión RC1.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/nueva-version-de-cakephp-disponible/feed</wfw:commentRss>
		</item>
		<item>
		<title>Sindicación de noticias</title>
		<link>http://cakephp.hospedaxes.com/sindicacion-de-noticias</link>
		<comments>http://cakephp.hospedaxes.com/sindicacion-de-noticias#comments</comments>
		<pubDate>Tue, 06 May 2008 14:51:16 +0000</pubDate>
		<dc:creator>nuria</dc:creator>
		
		<category><![CDATA[Noticias]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<category><![CDATA[feed]]></category>

		<category><![CDATA[RSS]]></category>

		<category><![CDATA[Sindicación de noticias]]></category>

		<category><![CDATA[sindicación web]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=16</guid>
		<description><![CDATA[Hoy vamos a explicar cómo hacer en CakePHP 1.2 un canal de sindicación de noticias o sindicación web. Es una funcionalidad que utilizamos con mucha frecuencia en nuestros diseños web y para la que Cake nos ofrece un buen soporte.
Cake nos proporciona un helper, RSSHelper, que nos permite hacer en muy pocas líneas de código [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy vamos a explicar cómo hacer en <a title="CakePHP" href="http://www.cakephp.org/">CakePHP 1.2</a> un canal de <a title="Artículo acerca de la sindicación web" href="http://es.wikipedia.org/wiki/Sindicación_web">sindicación de noticias o sindicación web</a>. Es una funcionalidad que utilizamos con mucha frecuencia en nuestros <a title="Hospedaxes" href="http://www.hospedaxes.com">diseños web</a> y para la que Cake nos ofrece un buen soporte.</p>
<p>Cake nos proporciona un helper, <a title="API del RSS Helper" href="http://api.cakephp.org/1.2/class_rss_helper.html">RSSHelper</a>, que nos permite hacer en muy pocas líneas de código un RSS.</p>
<p>Lo primero que tenemos que hacer es una función en el controlador o bien utilizar la misma función index del controlador que queramos sindicar:</p>
<div class="igBar"><span id="lphp-6"><a href="#" onclick="javascript:showPlainTxt('php-6'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> NoticiasController extends AppController</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$helpers</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Rss'</span>, <span style="color:#FF0000;">'Xml'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$components</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'RequestHandler'</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> index<span style="color:#006600; font-weight:bold;">&#40;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">RequestHandler</span>-&gt;<span style="color:#006600;">prefers</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'rss'</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span> = <span style="color:#FF0000;">'default'</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'channel'</span>,<a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'title'</span> =&gt; <span style="color:#FF0000;">'Portal web - Noticias'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'description'</span> =&gt; <span style="color:#FF0000;">'Sindicación de noticias de nuestro portal web'</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'link'</span> =&gt; <span style="color:#FF0000;">'http://url_al_portal.com'</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'data'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">Noticia</span>-&gt;<span style="color:#006600;">findAll</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#000000; font-weight:bold;">null</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Noticia.fecha DESC'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#CC66CC;color:#800000;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">else</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// Si no es un RSS, ponemos aquí cómo queremos que se comporte el index</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">redirect</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">"otra_funcion"</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="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>
Vemos que tuvimos que importar algunos helpers y componentes. Establecemos aquí ya el título, descripción y enlace del canal, y los datos que queremos sindicar.</p>
<p>En la capa de la vista, tenemos que definir el layout <em>default.ctp</em>, que estará en la carpeta <em>views/layout/rss</em> y será de una manera tan simple como la siguiente:</p>
<div class="igBar"><span id="lphp-7"><a href="#" onclick="javascript:showPlainTxt('php-7'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-7">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">&lt;?php</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$content_for_layout</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Y también definir la vista en si, que estará en nuestro caso en la carpeta views/noticias/rss y se llamará index.ctp, y que tendrá la forma:</p>
<div class="igBar"><span id="lphp-8"><a href="#" onclick="javascript:showPlainTxt('php-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-8">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> convertirRSS<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">return</span> <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'title'</span> =&gt; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Noticia'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'titulo'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'link'</span>&nbsp; =&gt; <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'action'</span> =&gt; <span style="color:#FF0000;">'ver'</span>, <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Noticia'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'url'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Noticia'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'id'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'description'</span> =&gt; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Noticia'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'texto'</span><span style="color:#006600; font-weight:bold;">&#93;</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'pubDate'</span> =&gt; <span style="color:#0000FF;">$data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Noticia'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'fecha'</span><span style="color:#006600; font-weight:bold;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$xml</span>-&gt;<span style="color:#006600;">header</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'version'</span>=&gt;<span style="color:#FF0000;">'1.0'</span>, <span style="color:#FF0000;">'encoding'</span>=&gt;<span style="color:#FF0000;">'utf-8'</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$document</span> = <span style="color:#0000FF;">$rss</span>-&gt;<span style="color:#006600;">channel</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0000FF;">$channel</span>, <span style="color:#0000FF;">$rss</span>-&gt;<span style="color:#006600;">items</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$data</span>, <span style="color:#FF0000;">'convertirRSS'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$rss</span>-&gt;<span style="color:#006600;">document</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'version'</span>=&gt;<span style="color:#FF0000;">'2.0'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#0000FF;">$document</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">?&gt;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Ya por último, lo único que tenemos que hacer es meter en la cabecera de nuestro código html, el link, para que nos ponga en la barra del navegador el enlace a nuestro rss:</p>
<div class="igBar"><span id="lphp-9"><a href="#" onclick="javascript:showPlainTxt('php-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-9">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;link rel=<span style="color:#FF0000;">"alternate"</span> type=<span style="color:#FF0000;">"application/rss+xml"</span> title=<span style="color:#FF0000;">"Nuestro portal web RSS Feed"</span> href=<span style="color:#FF0000;">"/noticias/index.rss"</span> /&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Y, como vemos, esta url no sigue el formato estándar de las urls que utiliza Cake, por lo que tenemos que definir en el archivo config/routes.php una regla para ello:</p>
<div class="igBar"><span id="lphp-10"><a href="#" onclick="javascript:showPlainTxt('php-10'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-10">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Router::<span style="color:#006600;">parseExtensions</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Con esto ya tendríamos definido el RSS para nuestra aplicación.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/sindicacion-de-noticias/feed</wfw:commentRss>
		</item>
		<item>
		<title>Separación de funcionalidades (similar a fachadas)</title>
		<link>http://cakephp.hospedaxes.com/separacion-de-funcionalidades-similar-a-fachadas</link>
		<comments>http://cakephp.hospedaxes.com/separacion-de-funcionalidades-similar-a-fachadas#comments</comments>
		<pubDate>Fri, 18 Apr 2008 06:56:02 +0000</pubDate>
		<dc:creator>nuria</dc:creator>
		
		<category><![CDATA[Noticias]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<category><![CDATA[admin]]></category>

		<category><![CDATA[administrador]]></category>

		<category><![CDATA[estructura]]></category>

		<category><![CDATA[fachadas]]></category>

		<category><![CDATA[organizacion]]></category>

		<category><![CDATA[panel]]></category>

		<category><![CDATA[separacion funcionalidades]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=7</guid>
		<description><![CDATA[CakePHP 1.2 nos proporciona un soporte con un significado similar al de las fachadas, que nos permite:

Separar los distintos tipos de funcionalidades en los controladores: podemos separar, por ejemplo, las funciones que corresponden al administrador, del resto de las funciones, simplemente iniciando el nombre de dicha función con la cadena "admin_".
Separar por urls los distintos [...]]]></description>
			<content:encoded><![CDATA[<p>CakePHP 1.2 nos proporciona un soporte con un significado similar al de las fachadas, que nos permite:</p>
<ul>
<li>Separar los distintos tipos de funcionalidades en los controladores: podemos separar, por ejemplo, las funciones que corresponden al administrador, del resto de las funciones, simplemente iniciando el nombre de dicha función con la cadena "admin_".</li>
<li>Separar por urls los distintos apartados: por ejemplo, para acceder a una función de un controlador que sea "admin_listar", tendremos que escribir la url: admin/controlador/listar. De esta forma sabemos en todo momento en qué parte de nuestro proyecto nos movemos.</li>
<li>Como consecuencia y para que nuestro proyecto mucho más organizado, separaremos también las vistas en función de si estamos en la sección del administrador o en las otras secciones.</li>
<li>Esto nos permitirá también realizar un tratamiento personalizado de cada sección: por ejemplo, en el <em>beforeFilter</em> del <em>AppController</em> le podemos introducir un filtro de login.</li>
</ul>
<p>Veamos cómo realizar la configuración de todo lo comentado. En el archivo <em>app/config/routes.php</em>, escribimos:</p>
<div class="igBar"><span id="lphp-14"><a href="#" onclick="javascript:showPlainTxt('php-14'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-14">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Configure::<span style="color:#006600;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Routing.admin'</span>, <span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
En el controlador:</p>
<div class="igBar"><span id="lphp-15"><a href="#" onclick="javascript:showPlainTxt('php-15'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-15">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> UsuariosController extends AppController</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$layout</span> = <span style="color:#FF0000;">'usuarios'</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> admin_listar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#FF9933; font-style:italic;">//Comandos}</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> listar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#FF9933; font-style:italic;">//Comandos }</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="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>
De esta manera podemos cambiar el layout en función de dónde nos encontremos y tenerlas estructuradas en distintas carpetas. Para ello, en el archivo <em>cake/libs/controller/app_controller.php</em> escribimos:</p>
<div class="igBar"><span id="lphp-16"><a href="#" onclick="javascript:showPlainTxt('php-16'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-16">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">class</span> AppController extends Controller</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> beforeFilter<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'action'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <a href="http://www.php.net/strstr"><span style="color:#000066;">strstr</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'action'</span><span style="color:#006600; font-weight:bold;">&#93;</span>, <span style="color:#FF0000;">'admin_'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span> = <span style="color:#FF0000;">'admin/'</span>.<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// O bien, comparando una variable que se almacena en &lt;em&gt;$this-&gt;data&lt;/em&gt;:</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#93;</span>==<span style="color:#CC66CC;color:#800000;">1</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span> = <span style="color:#FF0000;">'admin/'</span>.<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF9933; font-style:italic;">// La última posibilidad es comparando la variable &lt;em&gt;prefix&lt;/em&gt; de &lt;em&gt;$this-&gt;data&lt;/em&gt;:</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'prefix'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>&amp;&amp; <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">params</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'prefix'</span><span style="color:#006600; font-weight:bold;">&#93;</span>==<span style="color:#FF0000;">'admin'</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span> = <span style="color:#FF0000;">'admin/'</span>.<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">layout</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="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></p>
<p>Podríamos configurar tantas secciones como queramos simplemente añadiendo más líneas en el archivo <em>routes.php</em>, obteniendo un código mucho más limpio y legible.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/separacion-de-funcionalidades-similar-a-fachadas/feed</wfw:commentRss>
		</item>
		<item>
		<title>Paginación con ordenación por columna y buscador</title>
		<link>http://cakephp.hospedaxes.com/paginacion-con-ordenacion-por-columna-y-buscador</link>
		<comments>http://cakephp.hospedaxes.com/paginacion-con-ordenacion-por-columna-y-buscador#comments</comments>
		<pubDate>Thu, 03 Apr 2008 16:22:27 +0000</pubDate>
		<dc:creator>nuria</dc:creator>
		
		<category><![CDATA[Noticias]]></category>

		<category><![CDATA[Paginación 1.2]]></category>

		<category><![CDATA[cakephp-1.2]]></category>

		<category><![CDATA[ajax]]></category>

		<category><![CDATA[buscador]]></category>

		<category><![CDATA[ordenacion]]></category>

		<category><![CDATA[paginacion]]></category>

		<category><![CDATA[paginator]]></category>

		<category><![CDATA[request handler]]></category>

		<guid isPermaLink="false">http://www.hospedaxes.com/blog-cakephp/?p=8</guid>
		<description><![CDATA[Hoy vamos a hablar de cómo introducir en nuestro diseño web la paginación en CakePHP 1.2, introduciéndole un buscador. Utilizaremos una tabla para visualizar los datos, añadiéndole la opción de ordenarla pinchando en las cabeceras.
Utilizaremos para ello el Paginator Helper que viene implementado en esta nueva versión y que, como veremos, hace muchísimo más fácil [...]]]></description>
			<content:encoded><![CDATA[<p>Hoy vamos a hablar de cómo introducir en nuestro <a href="http://www.hospedaxes.com" target="_blank">diseño web</a> la paginación en <a href="http://www.cakephp.org" target="_blank">CakePHP 1.2</a>, introduciéndole un buscador. Utilizaremos una tabla para visualizar los datos, añadiéndole la opción de ordenarla pinchando en las cabeceras.</p>
<p>Utilizaremos para ello el <a href="http://api.cakephp.org/1.2/class_paginator_helper.html" target="_blank">Paginator Helper</a> que viene implementado en esta nueva versión y que, como veremos, hace muchísimo más fácil esta tarea.</p>
<p>Empezamos con el controlador. Lo primero que tenemos que hacer es añadir dos variables:</p>
<div class="igBar"><span id="lphp-20"><a href="#" onclick="javascript:showPlainTxt('php-20'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-20">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$paginate</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'limit'</span> =&gt;<span style="color:#CC66CC;color:#800000;">10</span>, <span style="color:#FF0000;">'page'</span> =&gt;<span style="color:#CC66CC;color:#800000;">1</span>, <span style="color:#FF0000;">'order'</span>=&gt;array<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Modelo.campo ASC'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">var</span> <span style="color:#0000FF;">$components</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'RequestHandler'</span><span style="color:#006600; font-weight:bold;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p>
como vemos en las opciones del array, le especificamos en la variable <em>limit</em> el número de elementos por página, en <em>page</em> la página en la que empezamos y en <em>order</em> la ordenación inicial. El componente <a href="http://api.cakephp.org/1.2/class_request_handler_component.html" target="_blank"><em>RequestHandler </em></a>no sería necesario si no introducimos el buscador.</p>
<p>El siguiente paso es crear una función de la manera siguiente:</p>
<div class="igBar"><span id="lphp-21"><a href="#" onclick="javascript:showPlainTxt('php-21'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-21">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#000000; font-weight:bold;">function</span> admin_listar<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">RequestHandler</span>-&gt;<span style="color:#006600;">isAjax</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'llamada_ajax'</span>, <span style="color:#CC66CC;color:#800000;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">Session</span>-&gt;<span style="color:#006600;">del</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">name</span>.<span style="color:#FF0000;">'.search'</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Modelo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cadena_busqueda'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$str</span> = <a href="http://www.php.net/trim"><span style="color:#000066;">trim</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Modelo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cadena_busqueda'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<a href="http://www.php.net/empty"><span style="color:#000066;">empty</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Modelo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cadena_busqueda'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span> &amp;&amp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">data</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Modelo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'cadena_busqueda'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#FF0000;">''</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">Session</span>-&gt;<span style="color:#006600;">del</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">name</span>.<span style="color:#FF0000;">'.search'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">elseif</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">Session</span>-&gt;<span style="color:#006600;">check</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">name</span>.<span style="color:#FF0000;">'.search'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$str</span> = <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">Session</span>-&gt;<span style="color:#006600;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">name</span>.<span style="color:#FF0000;">'.search'</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span>&nbsp; <span style="color:#0000FF;">$condicion</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/isset"><span style="color:#000066;">isset</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$str</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$condicion</span> = <span style="color:#FF0000;">"Modelo.campo LIKE <span style="color:#000099; font-weight:bold;">\"</span>%$str%<span style="color:#000099; font-weight:bold;">\"</span>"</span>;&nbsp; &nbsp;<span style="color:#FF9933; font-style:italic;">// Podemos poner la condición que nos interese</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">Session</span>-&gt;<span style="color:#006600;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">name</span>.<span style="color:#FF0000;">'.search'</span>, <span style="color:#0000FF;">$str</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'resultado'</span>, <span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">paginate</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Modelo'</span>, <span style="color:#0000FF;">$condicion</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">RequestHandler</span>-&gt;<span style="color:#006600;">isAjax</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'llamada_ajax'</span>, <span style="color:#CC66CC;color:#800000;">1</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$this</span>-&gt;<span style="color:#006600;">render</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'admin_listar'</span>, <span style="color:#FF0000;">'ajax'</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="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>
Utilizaremos la sesión para guardar la cadena de búsqueda y no perderla cuando pulsemos en las cabeceras para la ordenación.</p>
<p>Y la vista sería ("admin_listar.ctp"):</p>
<div class="igBar"><span id="lphp-22"><a href="#" onclick="javascript:showPlainTxt('php-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-22">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span>!<span style="color:#0000FF;">$llamada_ajax</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$form</span>-&gt;<span style="color:#006600;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Modelo'</span>,<a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'action'</span>=&gt;<span style="color:#FF0000;">''</span>, <span style="color:#FF0000;">'id'</span>=&gt;<span style="color:#FF0000;">'buscar'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$form</span>-&gt;<span style="color:#006600;">input</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Modelo.cadena_busqueda'</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</span>=&gt;<span style="color:#FF0000;">'cadena_busqueda'</span>, <span style="color:#FF0000;">'label'</span>=&gt;<span style="color:#FF0000;">'Búsqueda'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;&nbsp; <span style="color:#0000FF;">$options</span> = <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'frequency'</span>=&gt;<span style="color:#FF0000;">'2'</span>, <span style="color:#FF0000;">'url'</span> =&gt; <span style="color:#FF0000;">'listar'</span>, <span style="color:#FF0000;">'update'</span> =&gt; <span style="color:#FF0000;">'listado'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'loading'</span> =&gt; <span style="color:#FF0000;">'Element.show(<span style="color:#000099; font-weight:bold;">\'</span>LoadingDiv<span style="color:#000099; font-weight:bold;">\'</span>)'</span>,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'complete'</span> =&gt; <span style="color:#FF0000;">'Element.hide(<span style="color:#000099; font-weight:bold;">\'</span>LoadingDiv<span style="color:#000099; font-weight:bold;">\'</span>)'</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$ajax</span>-&gt;<span style="color:#006600;">submit</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Buscar'</span>,<span style="color:#0000FF;">$options</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$form</span>-&gt;<span style="color:#006600;">end</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$html</span>-&gt;<span style="color:#006600;">div</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#000000; font-weight:bold;">null</span>, <span style="color:#0000FF;">$html</span>-&amp;gt;image<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'ajax-loader.gif'</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'id'</span>=&gt;<span style="color:#FF0000;">'LoadingDiv'</span>, <span style="color:#FF0000;">'style'</span>=&gt;<span style="color:#FF0000;">'display: none;'</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#0000FF;">$paginator</span>-&gt;<span style="color:#006600;">options</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'update'</span>=&gt;<span style="color:#FF0000;">'listado'</span>,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'url'</span>=&gt;array<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'controller'</span>=&gt;<span style="color:#FF0000;">'nombre_controlador'</span>, <span style="color:#FF0000;">'action'</span>=&gt;<span style="color:#FF0000;">'listar'</span><span style="color:#006600; font-weight:bold;">&#41;</span> ,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#FF0000;">'indicator'</span> =&gt; <span style="color:#FF0000;">'LoadingDiv'</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">if</span> <span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/count"><span style="color:#000066;">count</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$resultado</span><span style="color:#006600; font-weight:bold;">&#41;</span>&gt;<span style="color:#CC66CC;color:#800000;">0</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"Página "</span>.<span style="color:#0000FF;">$paginator</span>-&gt;<span style="color:#006600;">counter</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'separator'</span>=&gt;<span style="color:#FF0000;">' de '</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$html</span>-&amp;gt;table<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'listado'</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;thead class='cabecera'&gt;"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;tr&gt;&lt;th&gt;"</span>.<span style="color:#0000FF;">$paginator</span>-&gt;<span style="color:#006600;">sort</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Título cabecera'</span>, <span style="color:#FF0000;">'campo_modelo'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#FF0000;">"&lt;/th&gt;&lt;/tr&gt;"</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#FF0000;">"&lt;/thead&gt;"</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#616100;">foreach</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$resultado</span> <span style="color:#616100;">as</span> <span style="color:#0000FF;">$elemento</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$html</span>-&gt;<span style="color:#006600;">tableCells</span><span style="color:#006600; font-weight:bold;">&#40;</span> <a href="http://www.php.net/array"><span style="color:#000066;">array</span></a> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF;">$elemento</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'Modelo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#FF0000;">'campo_modelo'</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$html</span>-&gt;<span style="color:#006600;">tableEnd</span><span style="color:#006600; font-weight:bold;">&#40;</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$paginator</span>-&gt;<span style="color:#006600;">prev</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Página anterior'</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$paginator</span>-&gt;<span style="color:#006600;">numbers</span><span style="color:#006600; font-weight:bold;">&#40;</span><a href="http://www.php.net/array"><span style="color:#000066;">array</span></a><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'separator'</span>=&gt;<span style="color:#FF0000;">' - '</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$paginator</span>-&gt;<span style="color:#006600;">next</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'Página siguiente'</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="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#616100;">else</span> <span style="color:#006600; font-weight:bold;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color:#000066;">echo</span></a> <span style="color:#0000FF;">$html</span>-&gt;<span style="color:#006600;">para</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#FF0000;">'clase'</span>,<span style="color:#FF0000;">'No se han encontrado resultados.'</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="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>
Vemos aquí que es el propio Paginator Helper el que, con una simple llamada a la función <em>sort</em>, ya se encarga de hacer la ordenación de la columna alternando en cada click entre ascendente y descendente.</p>
<p>La función <em>counter </em>nos devuelve una cadena con la página en la que nos encontramos y el número total de páginas, en nuestro caso introducimos la cadena ' de ', entre ellas.</p>
<p>Y por último, las tres últimas funciones utilizadas, <em>prev</em>, <em>numbers </em>y <em>next</em>, nos muestran los enlaces a la página previa, a cada una de las páginas y a la página siguiente, respectivamente.</p>
<p>CakePHP 1.2 nos proporciona muchas más posibilidades y muchas otras opciones. Podemos obtener más información en la <a href="http://api.cakephp.org/1.2/" target="_blank">especificación de CakePHP 1.2</a> del <a href="http://api.cakephp.org/1.2/class_paginator_helper.html" target="_blank">Paginator Helper</a>. Así como en la Bakery, en la que tenemos un artículo sobre la <a href="http://bakery.cakephp.org/articles/view/basic-pagination-overview-3" target="_blank">paginación básica</a> y otro sobre la <a href="http://bakery.cakephp.org/articles/view/advanced-pagination-1-2" target="_blank">avanzada</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/paginacion-con-ordenacion-por-columna-y-buscador/feed</wfw:commentRss>
		</item>
	</channel>
</rss>
