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

<channel>
	<title>Blog cakephp en español por Hospedaxes &#187; ajax</title>
	<atom:link href="http://cakephp.hospedaxes.com/tag/ajax/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>
	<lastBuildDate>Mon, 26 Apr 2010 07:11:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tree Behavior o cómo crear una estructura jerárquica</title>
		<link>http://cakephp.hospedaxes.com/tree-behavior-o-como-crear-una-estructura-jerarquica</link>
		<comments>http://cakephp.hospedaxes.com/tree-behavior-o-como-crear-una-estructura-jerarquica#comments</comments>
		<pubDate>Wed, 14 Oct 2009 08:42:33 +0000</pubDate>
		<dc:creator>nuria</dc:creator>
				<category><![CDATA[Noticias]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[árbol]]></category>
		<category><![CDATA[cakephp 1.2]]></category>
		<category><![CDATA[organización jerárquica]]></category>
		<category><![CDATA[tree behavior]]></category>

		<guid isPermaLink="false">http://cakephp.hospedaxes.com/?p=237</guid>
		<description><![CDATA[En esta ocasión hablaremos de cómo crear una estructura jerárquica utilizando el Tree Behavior de CakePHP. Este comportamiento facilita muchísimo las cosas a la hora de manipular árboles jerárquicos de datos.
Utilizaremos también la librería de Javascript Ext JS para poder manipular el árbol gráficamente de manera sencilla, utilizando drag and drop.
Lo primero que tendremos que [...]]]></description>
			<content:encoded><![CDATA[<p>En esta ocasión hablaremos de cómo crear una estructura jerárquica utilizando el <a title="CakePHP: Tree Behavior" href="http://api.cakephp.org/class/tree-behavior">Tree Behavior</a> de CakePHP. Este comportamiento facilita muchísimo las cosas a la hora de manipular árboles jerárquicos de datos.</p>
<p>Utilizaremos también la librería de Javascript <a title="Ext JS" href="http://www.extjs.com/">Ext JS</a> para poder manipular el árbol gráficamente de manera sencilla, utilizando <a title="Wikipedia: Arrastrar y soltar" href="http://es.wikipedia.org/wiki/Arrastrar_y_soltar"><em>drag and drop</em></a>.</p>
<p>Lo primero que tendremos que hacer será añadir en la tabla de la base de datos de la entidad. Utilizando los nombres por defecto de Cake, serían los siguientes campos:</p>
<ul>
<li><em>parent_id</em>: hace referencia al padre del elemento.</li>
<li><em>lft</em>: almacena el identificador del elemento de la izquierda en el mismo nivel.</li>
<li><em>rght</em>: almacena el identificador del elemento de la derecha en el mismo nivel.</li>
</ul>
<p>Incluiremos también los campos <em>id</em> y <em>nombre</em>, en una entidad denominada, por ejemplo, Categoria.</p>
<p>El modelo lo haríamos de la siguiente manera:</p>
<p>Este comportamiento tiene funciones muy útiles para la manipulación del árbol. Las más utilizadas quizás sean las siguientes:</p>
<ul>
<li><strong><em>children</em></strong>: devuelve los hijos de un nodo concreto, pudiendo seleccionar si deseamos obtener sólo los hijos directos o todos los hijos en el árbol.</li>
<li><strong><em>generatetreelist</em></strong>: función muy útil para obtener los elementos a introducir en un select de HTML.</li>
<li><strong>getpath</strong>: devuelve todo el path hasta el nodo especificado en un array.</li>
<li><strong>movedown</strong> y <strong>moveup</strong>: sirven para bajar o subir un nivel de un nodo del árbol.</li>
<li><strong>removefromtree</strong>: elimina un nodo del árbol sin perder la estructura, es decir, modificando el padre de sus hijos.</li>
<li><strong>reorder</strong>: reordena un nodo (arrastrando también a sus hijos) en función de los parámetros especificados.</li>
</ul>
<p>Para realizar la manipulación visual del árbol de categorías crearemos las siguientes funciones en el controlador <em>app/controllers/categorias_controller.php</em> sería:</p>
<pre class="prettyprint"><code>&lt;?php

class CategoriasController extends AppController{

var $helpers = array( 'Javascript');

// Función para organizar las categorías
function organizar() {}

function getnodes() {
   Configure::write('debug', 0);
   // obtener el identificador del padre que se envío por POST vía Ajax
   $parent = intval($this-&gt;params['form']['node']);
   // encontrar los hijos directos del nodo anterior
   $nodes = $this-&gt;Categoria-&gt;children($parent, true, null, 'Categoria.lft ASC');

   $this-&gt;set(compact('nodes'));

   $this-&gt;render('getnodes', 'ajax');
}

function reorder()
{
   Configure::write('debug', 0);

   // delta es la diferencia en la posición (1 = nodo siguiente, -1 = nod anterior)
   $node = intval($this-&gt;params['form']['node']);
   $delta = intval($this-&gt;params['form']['delta']);

   if ($delta &gt; 0) {
      $this-&gt;Categoria-&gt;movedown($node, abs($delta));
   } elseif ($delta &lt; 0) {
      $this-&gt;Categoria-&gt;moveup($node, abs($delta));
   }

   exit('1');
}

function reparent()
{
   Configure::write('debug', 0);

   $node = intval($this-&gt;params['form']['node']);
   $parent = intval($this-&gt;params['form']['parent']);
   $position = intval($this-&gt;params['form']['position']);

   // guardamos el nuevo padre de la categoría
   $this-&gt;Categoria-&gt;id = $node;
   $this-&gt;Categoria-&gt;saveField('parent_id', $parent);

   // Si position == 0, nos movemos al inicio.
   // En otro caso, calculamos la distancia que nos moveremos ($delta).
   if ($position == 0) {
      $this-&gt;Categoria-&gt;moveup($node, true);
   } else {
      $count = $this-&gt;Categoria-&gt;childcount($parent, true);
      $delta = $count - $position - 1;
      if ($delta &gt; 0) {
         $this-&gt;Categoria-&gt;moveup($node, $delta);
      }
   }

   exit('1');
}
}
?&gt;</code></pre>
<p>Sólo nos quedaría hacer las vistas. En este caso, necesitamos crear 2 vistas: organizar.ctp y getnodes.ctp.</p>
<pre class="prettyprint"><code>// app/views/categorias/organizar.ctp

&lt;?php echo $html-&gt;css('/js/ext-2.0.1/resources/css/ext-custom.css'); ?&gt;
&lt;?php echo $javascript-&gt;link('/js/ext-2.0.1/ext-custom.js'); ?&gt;

&lt;script type="text/javascript"&gt;
Ext.BLANK_IMAGE_URL = '&lt;?php echo $html-&gt;url('/js/ext-2.0.1/resources/images/default/s.gif') ?&gt;';

Ext.onReady(function(){

   var getnodesUrl = '&lt;?php echo $html-&gt;url('/categorias/getnodes') ?&gt;';
   var reorderUrl = '&lt;?php echo $html-&gt;url('/categorias/reorder') ?&gt;';
   var reparentUrl = '&lt;?php echo $html-&gt;url('/categorias/reparent') ?&gt;';

   var Tree = Ext.tree;

   var tree = new Tree.TreePanel({
      el:'tree-div',
      autoScroll:true,
      animate:true,
      enableDD:true,
      containerScroll: true,
      rootVisible: true,
      loader: new Ext.tree.TreeLoader({
         dataUrl:getnodesUrl
      })
    });

   var root = new Tree.AsyncTreeNode({
      text:'Categorías',
      draggable:false,
      id:'root'
   });

   tree.setRootNode(root);
   tree.setHeight('auto');

   var oldPosition = null;
   var oldNextSibling = null;

   tree.on('startdrag', function(tree, node, event){
      oldPosition = node.parentNode.indexOf(node);
      oldNextSibling = node.nextSibling;
   });

   tree.on('movenode', function(tree, node, oldParent, newParent, position){

   if (oldParent == newParent){
      var url = reorderUrl;
      var params = {'node':node.id, 'delta':(position-oldPosition)};
   } else {
      var url = reparentUrl;
      var params = {'node':node.id, 'parent':newParent.id, 'position':position};
   }

tree.disable();

Ext.Ajax.request({
   url:url,
   params:params,
   success:function(response, request) {
      // if the first char of our response is zero, then we fail the operation,
      // otherwise we re-enable the tree
      if (response.responseText.charAt(0) != 1){
         request.failure();
      } else {
         tree.enable();
      }
   },
   failure:function() {
      // we move the node back to where it was beforehand and
      // we suspendEvents() so that we don't get stuck in a possible infinite loop
      tree.suspendEvents();
      oldParent.appendChild(node);
      if (oldNextSibling){
         oldParent.insertBefore(node, oldNextSibling);
      }
      tree.resumeEvents();
      tree.enable();
      alert("Oh no! Your changes could not be saved!");
   }
});
});

tree.render();
root.expand();
});
&lt;/script&gt;

&lt;div id="tree-div"&gt;&lt;/div&gt;</code></pre>
<p>Y la última vista:</p>
<pre class="prettyprint"><code>&lt;?php
// app/views/categorias/getnodes.ctp
$data = array();
foreach ($nodes as $node)
{</code>   <code>$data[] = array(</code>      <code>"text" =&gt; $node['Categoria']['nombre'],</code>      <code>"id" =&gt; $node['Categoria']['id']</code>   <code>);
}
echo $javascript-&gt;object($data);
?&gt;</code></pre>
<p>Ya sólo nos quedaría descargarnos la librería <a title="Ext JS" href="http://www.extjs.com/" target="_blank">ExtJS</a> y copiarla en la carpeta /app/webroot/js. En el <a title="Demostración de funcionamiento de Ext JS" href="http://cakephp.hospedaxes.com/pruebas/tree_behavior">ejemplo</a>, se ha utilizado la versión 2.0.1.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 289px; width: 1px; height: 1px;">
<pre style="display: block;">Categoria</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://cakephp.hospedaxes.com/tree-behavior-o-como-crear-una-estructura-jerarquica/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</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>
		<slash:comments>29</slash:comments>
		</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-4"><a href="#" onclick="javascript:showPlainTxt('php-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-4">
<div class="php">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="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-5"><a href="#" onclick="javascript:showPlainTxt('php-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">PHP:</span>
<div id="php-5">
<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-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:#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>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

