Jump to content


Photo

Digg Paginação No Cake


  • Faça o login para participar
2 replies to this topic

#1 destrutorx

destrutorx

    Hell Yes!

  • Usuários
  • 175 posts
  • Sexo:Masculino
  • Localidade:Nova Iguaçu - RJ
  • Interesses:Quadrinhos, cinema, musica, programação, internet

Posted 11/11/2009, 12:24

Estou tentando aplicar uma paginação numa página de noticias mas sem obter sucesso... Não exibe a numeração... será que podem me dar um Help e me ajudar a enxergar o erro?

controller
class NoticiasController extends AppController { //O nome do controller deve ser sempre no plural e seguido da palavra “Controller”.
	var $name = "Noticias"; //Compatibilidade com PHP 4
	var $uses = array('Noticia'); //Model Utilizado. O nome de model é sempre singular.
	var $helpers = array('Html','Javascript','Pagination'); //Carregando Helpers
	
	function index($page=1){
	
	$this->set('pag_link', '/noticias/'); 
		$this->set('pag_page', $page); 
		$this->set('pag_total', $this->Noticia->contaTudo()); 
	}
	
}

model
class Noticia extends AppModel {
	var $name = "Noticia"; //Compatibilidade com PHP 4
	
	function listaTudo(){ 
				return $this->query('SELECT * FROM noticias ORDER BY data DESC', $cachequeries = false); 
		}
	
	function contaTudo(){
		$sql = 'SELECT * FROM noticias ORDER BY data DESC';
		$results = $this->query($sql, $cachequeries = false);
		return count($results);
	}
	
}

view
<?php //Passando CSS da página para o layout ?>
<?php e($html->css('estilos', array(), array('media'=>'screen'), false) . "\n"); ?>

<?php //Passando Javascript da página para o layout ?>
<?php e($javascript->link('jquery.min', false) . "\n"); ?>

<h2>Noticias</h2>

<p>As noticias mais quentes você acompanha aqui.</p>

<?php $pagination->paginate($pag_link, $pag_page, $pag_total); ?>


Desde já agradeço

#2 Squall Robert

Squall Robert

    Mr. Squall - Mais Carne do que Osso (hihi)

  • Usuários
  • 507 posts
  • Sexo:Masculino
  • Localidade:Curitiba
  • Interesses:Php ... Php...Php

Posted 12/11/2009, 09:22

impossivel te ajudar... com o que vc colocou ai...

vc colocou partes de algumas classses.. mas que não define nada do sistema

nao tem como saber sem ver todos os objetos que estão sendo usados no problema acima
<?php

$squall = new Squall();

$squall->Ajudando("você");

$resultado = $squall->solucao();  ?>

#3 destrutorx

destrutorx

    Hell Yes!

  • Usuários
  • 175 posts
  • Sexo:Masculino
  • Localidade:Nova Iguaçu - RJ
  • Interesses:Quadrinhos, cinema, musica, programação, internet

Posted 12/11/2009, 10:18

O Controller se chama 'noticias_controller.php' .
O Model se chama 'noticia.php' .

Acho que tá seguindo as regras do cakePHP...

Faltou o Helper...

pagination.php
class PaginationHelper extends HtmlHelper
{
	
	function paginate( $link, $page, $total, $show=5, $skip='&hellip;' )
	{
		/*
			$link	string of what link is to be (utilizes $html->link helper)... page numbers will be appended to its end
			$page	int current page you're on
			$total	int total number of pages
			$show	int how many page numbers / "skips" to show between first and last numbers
			$skip	string text to be displayed for "skips"... inside <span>
		*/

		// Get out early if there's no total pages
		if ( $total < 1 ) return false;

		// Init
		if ( $show < 1 ) $show = 1;						// make sure you're showing at least 1
		$show_mid = ceil( $show / 2 );					// find the midpoint of the shown page numbers / skips
		$skip = '<span class="skip">'.$skip.'</span>';	// add spans around skip text
		$out = "\n";

		// Figure out start point for In-between numbers
		if ( $page <= $show_mid ) $start = 2;
		elseif ( $page > ($total-$show) ) $start = $total - $show;
		else $start = $page - $show_mid + 1;

		// Previous link
		$out .= ( ($page-1) > 0 )
					? $this->link( 'Prev', $link.($page-1), array('title'=>'View the previous index page', 'class'=>'prev') ) 
					: '<span class="prev">Prev</span>';
		$out .= "\n";

		// First number
		$out .= ( $page == 1 )
					? '<span class="current">1</span>'
					: $this->link( '1', $link.'1', array('title'=>'View index page 1') );
		$out .= "\n";

		// In-between numbers
		for ( $i=0; $i<( ($total<$show+2) ? $total-2 : $show ); $i++ )
		{
			// First in-between number...
			if ( $i == 0 )
			{
				$out .= ( $start == 2 ) 
							? ( $page == 2 )
								? '<span class="current">2</span>'
								: $this->link( '2', $link.'2', array('title'=>'View index page 2') )
							: $skip;
			}

			// Last in-between number...
			elseif ( $i == ($show-1) )
			{
				$out .= ( $start >= ($total-$show) ) 
							? ( $page == ($total-1) )
								? '<span class="current">'.($total-1).'</span>'
								: $this->link( ($total-1), $link.($total-1), array('title'=>'View index page '.($total-1)) )
							: $skip;
			}

			// Else...
			else 
			{
				$out .= ( $page == ($start+$i) )
							? '<span class="current">'.($start+$i).'</span>'
							: $this->link( ($start+$i), $link.($start+$i), array('title'=>'View index page '.($start+$i)) );
			}

			$out .= "\n";
		}

		// Last number
		if ( $total > 1 )
		{
			$out .= ( $page == $total )
						? '<span class="current">'.$total.'</span>'
						: $this->link( $total, $link.$total, array('title'=>'View index page '.$total) );
			$out .= "\n";
		}

		// Next link
		$out .= ( ($page+1) <= $total )
					? $this->link( 'Next', $link.($page+1), array('title'=>'View the next index page', 'class'=>'next') )
					: '<span class="next">Next</span>';
		$out .= "\n";

		// Return
		return $out;
	}

}





1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq