Autor | Zpráva | ||
---|---|---|---|
Tirus Profil |
#1 · Zasláno: 20. 6. 2011, 21:34:40
Lidi, potřeboval bych poradit jak asi tak napsat třídu pro vygenerování stringu se stránkováním... jako vstup do této třídy by bylo o jakou se jedná stránku, a kolik je maximum stránek a také po kolika se stránkuje.. další by byl string v jakém formátu by byl odkaz, např. 'www.mujweb.cz/page=#n#' kde #n# by se nahradilo za cislo stranky...
morduju se tu s tím 2 dny a nejsem schopnej udělat ani generování toho stringu.. furt někde mám chybu |
||
panther Profil |
#2 · Zasláno: 20. 6. 2011, 22:30:58
Tirus:
„morduju se tu s tím 2 dny a nejsem schopnej udělat ani generování toho stringu.. furt někde mám chybu“ ukaž, co máš a chybu najdeme. |
||
Tirus Profil |
#3 · Zasláno: 20. 6. 2011, 22:57:18 · Upravil/a: Tirus
můj kod nemá smysl moc komentovat... jsem v něm zamotanej
a prosím... stále se učím OOP <?php class Paging { private $separator; public $output; private $totalcount; private $args; private $registry; private $offset; private $pattern = array('active' => '<strong>#page_number#</strong>', // klasicke strankovani, aktivni polozka 'link' => '<a href="#page_number#" >#page_number#</a>', // format odkazu 'separator' => ' <span>|</span> ', // oddelovac 'dots' => ' ... ', // 3 tecky pro vystup ve tvaru 1 | 2 | 3 ... 'dash' => '-', // pomlcka, pro strankovani ve tvaru 1-10 | 11-20 'marks' => array( // pole pro vystup ve tvaru << < 3 | 4 | 5 > >> 'laquo' => '«', 'raquo' => '»', 'lt' => '<', 'gt' => '>', ), ); private $page; function __construct($registry, $separator) { $this->registry = $registry; $this->args = $registry['args']; $this->getSeparator($separator); } public function createPaging($totalcount, $limit, $page, $site) { $this->limit = $limit; $this->offset = ($page * $limit) - $limit; $this->page = $page; $this->createOutput($site); } private function getSeparator($separator) { switch ($separator) { case 1: $this->separator = $this->pattern['separator']; break; case 2: $this->separator = $this->pattern['dots']; break; case 3: $this->separator = $this->pattern['dash']; break; default: $this->separator = $this->pattern['separator']; break; } } private function createOutput($site) { $this->totalcount = 1000; $this->offset = 998; $this->page = 149; if ($this->separator != $this->pattern['separator']) { $this->output .= '<a href="' . $this->registry['mysite'] . $site . '">' . $this->pattern['marks']['lt'] . '</a> ' . $this-> pattern['marks']['laquo']; } if ($this->offset <= 2) { $this->output .= ' 1 | 2 | 3 | 4 | 5'; } elseif ($this->offset >= ($this->totalcount - 2)) { for ($start = $this->totalcount - 5; $start == $this->totalcount; $start++) { $this->output .= ' ' . $start . $this->separator; } } else { $this->output .= ' ' . $this->pattern['dots']; for ($start = ($this->page - 2); $start <= $this->page; $start++) { $this->output .= $this->separator. $start; } for ($end = ($this->page+1); $end >= ($this->page + 2); $end++) { $this->output .= $this->separator. $start; } $this->output .= ' ' . $this->pattern['dots']; } if ($this->separator != $this->pattern['separator']) { $this->output .= $this->pattern['marks']['raquo'] . ' <a href="' . $this->registry['mysite'] . $site . '/'.$this->totalcount.'">' .$this-> pattern['marks']['gt'] . '</a> '; } echo $this->output; } } |
||
Časová prodleva: 13 let
|
0