Paginador

edited julio 2008 in Principiantes
Alguien puede postear algun codigo que muestre el uso del paginador en la version 0.5.
Gracias.

Comentarios

  • class UsuarioController extends ApplicationController {
    	private $_per_page = 7;
    
    	/**
    	 * Formulario de busqueda
    	 **/
    	public function buscar() {
    		$this->nullify('page', 'conditions');
    	}
    
    	/**
    	 * Paginador
    	 **/
    	public function lista($page='') {
    		/**
    		 * Cuando se efectua la busqueda por primera vez
    		 **/
    		if($this->has_post('usuario')) {
    			$usuario = $this->post('usuario', 'trim', 'addslashes');
    			if($usuario['nombre']) {
    				$this->conditions = “ nombre LIKE '%{$usuario['nombre']}%' ”;
    			}
    
    			/**
    			 * Paginador con condiciones o sin condiciones
    			 **/
    			if(isset($this->conditions) && $this->conditions) {
    				$this->page = $this->Usuario->paginate($this->conditions, “per_page: $this->_per_page”, 'page: 1');
    			} else {
    				$this->page = $this->Usuario->paginate(“per_page: $this->_per_page”, 'page: 1');
    			}
    		} elseif($page='next' && isset($this->page) && $this->page->next) {
    			/**
    			 * Paginador de pagina siguiente
    			 **/
    			if(isset($this->conditions) && $this->conditions) {
    				$this->page = $this->Usuario->paginate($this->conditions, “per_page: $this->_per_page”, “page: {$this->page->next}”);
    			} else {
    				$this->page = $this->Usuario->paginate(“per_page: $this->_per_page”, “page: {$this->page->next}”);
    			}
    
    		} elseif($page='prev' && isset($this->page) && $this->page->prev) {
    			/**
    			 * Paginador de pagina anterior
    			 **/
    			if(isset($this->conditions) && $this->conditions) {
    				$this->page = $this->Usuario->paginate($this->conditions, “per_page: $this->_per_page”, “page: {$this->page->prev}”);
    			} else {
    				$this->page = $this->Usuario->paginate(“per_page: $this->_per_page”, “page: {$this->page->prev}”);
    			}
    		}
    	}
    }
    

    Vista busca.phtml
    <?= form_tag('usuario/lista') ?>
    	<?= text_field_tag('usuario.nombre') ?>
    	<?= submit_tag('Consultar') ?>
    <?= end_form_tag() ?>
    

    Vista listar.phtml
    <table>
    <tr>
    	<th>id</th>
    	<th>nombre</th>
    </tr>
    <?php foreach($page->items as $p): ?>
    <tr>
    	<td><?= $p->id ?></td>
    	<td><?= h($p->nombre) ?></td>
    </tr>
    <?php endforeach; ?>
    </table>
    
    <br>
    
    <?php if($page->prev) echo link_to('usuario/lista/prev', 'Anterior') ?>
    <?php if($page->next) echo ' | ' . link_to('usuario/lista/next', 'Siguiente') ?>
    
  • edited 5:32
    Muchas gracias.
Sign In or Register to comment.