Вы не зашли.
Главная » PHP » Функция навигации по страницам
#11. tipsun Off (19)
Moderator
2011.10.28 22:10
Дык сыро еще же, не?
Или надо описать код/переменные/мое_восприятие_кода?
- - - -
Понял, описать код надо...
- - - -
Описал, поймите меня правильно smile
Отредактировано tipsun (2011.10.28 23:11)
#12. Gemorroj Off (107)
Administrator
2011.10.28 23:11
есть стандартизованный стиль описания кода. называется phpDoc... )
#13. tipsun Off (19)
Moderator
2011.10.28 23:11
Ок, буду знать.
Хотя я и так еле описал код. Сам код понимаю, а вот описать сложно.
#14. tipsun Off (19)
Moderator
2011.10.30 21:09
Есть замечания по классу моему?
- - - -
Я еще думаю может через static тоже принимать/отдавать значения.
Код:
span style="color: #0000BB"><?phppager::setItems(10);pager::setMethod('array');//или так путаница будет? типа лишнее??>
Отредактировано tipsun (2011.10.30 22:10)
#15. Gemorroj Off (107)
Administrator
2011.10.30 23:11
tipsun, сделай документацию в phpDoc стиле. Ориентироваться по ней проще будет для анализа.
#16. tipsun Off (19)
Moderator
2011.11.06 19:07
Код:
span style="color: #0000BB"><?php/** * pager * * @access public */class pager { private $count, $page, $pages, $start, $stop, $items = 10, $methods = array('array'=>0, 'table'=>0); /** * pager::__construct() * * @param string $count * @param string $page * @param string $items * @return null */ public function __construct($count='', $page='', $items='') { if (is_numeric($count) and 0 < $count) { $this->count = $count; } else { trigger_error('Count number of the items is not numeric', E_USER_ERROR); } if (is_numeric($items) and 0 < $items and $this->count >= $items) { $this->items = $items; } $this->pages = ceil($this->count / $this->items); $this->page = min(max(1, (int)$page), $this->pages); } /** * pager::calc() * * @param mixed $method * @return null */ private function calc($method) { $this->start = ($this->page -1) * $this->items; $this->stop = 0; if('array' == $method) $this->stop = min(($this->start +$this->items), $this->count); if('table' == $method) $this->stop = $this->items; } /** * pager::method() * * @uses function pager::calc() * * @param string $method * @return null */ public function method($method='undefined') { if (array_key_exists($method, $this->methods)) { self::calc($method); } else { trigger_error('Nonexistent method', E_USER_ERROR); } } /** * pager::page() * * @return integer param pager::page */ public function page() { return $this->page; } /** * pager::pages() * * @return integer param pager::pages */ public function pages() { return $this->pages; } /** * pager::start() * * @return integer param pager::start */ public function start() { if ($this->start) return $this->start; else trigger_error('Missing indication of method of calculation', E_USER_ERROR); } /** * pager::stop() * * @return integer param pager::stop */ public function stop() { if ($this->stop) return $this->stop; else trigger_error('Missing indication of method of calculation', E_USER_ERROR); } /** * pager::down() * * returns the number of the previous page * * @return integer */ public function down() { return 1 < $this->page ? $this->page -1 : $this->page; } /** * pager::up() * * returns the number of the next page * * @return integer */ public function up() { return $this->pages > $this->page ? $this->page +1 : $this->page; } }?>
Отредактировано tipsun (2011.11.06 20:08)
#17. tipsun Off (19)
Moderator
2011.11.09 21:09
Такое ощущение появилось, что я давно уже изобретаю велосипед (Zend Paginator). big_smile
А честно говоря зато я весь этот код теперь понимаю, хоть какой-то толк есть...

Код:
span style="color: #0000BB"><?phpclass pageMan { private $count = null, $page = null, $tmp_page = 1, $pages = null, $start = null, $stop = null; private static $items = 10, $methods = array('array'=>0, 'table'=>0); public function __construct($method, $count, $page, $items=null) { if (array_key_exists($method, self::$methods)) { $this->$method = $method; } else { trigger_error('Nonexistent method', E_USER_ERROR); } if (is_int($count) and 0 < $count) { $this->count = $count; } else { trigger_error('Value must be integer', E_USER_ERROR); } if (is_int($page) and 0 < $page) { $this->tmp_page = $page; } if (is_int($items)) { if (0 < $items) $this->items = $items; else $this->items = $this->count; } else { $this->items = self::$items; } } private function countPages() { if (null === $this->pages) { $this->pages = $this->count / $this->items; } return $this->pages; } public function getPages() { return self::countPages(); } private function setPage() { if (null === $this->page) { $this->page = min($this->tmp_page, self::countPages()); } return $this->page; } public function getPage() { return self::setPage(); } private function setStart() { if (null === $this->start) { $this->start = (self::setPage() - 1) * $this->items; } return $this->start; } public function getStart() { return self::setStart(); } private function setStop() { if('array' == $this->method) $this->stop = min((self::setStart() + $this->items), $this->count); if('table' == $this->method) $this->stop = $this->items; return $this->stop; } public function getStop() { return self::setStop(); } public function prevPage() { if (null === $this->page) { self::setPage(); } return 1 < $this->page ? $this->page - 1 : $this->page; } public function nextPage() { if (null === $this->pages) { self::countPages(); } if (null === $this->page) { self::setPage(); } return $this->pages > $this->page ? $this->page + 1 : $this->page; } }/**/?>
Отредактировано tipsun (2011.11.09 21:09)
#18. Gemorroj Off (107)
Administrator
2011.11.09 22:10
ну так да.. это главная цель велосипедов)
#19. tipsun Off (19)
Moderator
2011.11.10 20:08
Сделал через:
Код:
span style="color: #0000BB"><?php//__constructif (method_exists(__CLASS__, 'method_' . $method)) $this->method = $method;private function method_array() { /* CODE */ }private function method_table() { /* CODE */ }public function getStop() {return call_user_method($this->method, $this);}?>
Отредактировано tipsun (2011.11.10 21:09)
#20. tipsun Off (19)
Moderator
2011.11.11 15:03
Какой способ лучше?
Вложения
pageMan.php.txt 4kb [загрузок: 537]
pageMan_v2.php.txt 4kb [загрузок: 565]
Отредактировано tipsun (2011.11.11 15:03)
Страниц: 1 2 3 416 Все
Главная
WEB
PunBB Mod v0.6.2
0.022 s