Changeset 443
- Timestamp:
- 08/29/2007 12:02:58 PM (14 months ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
application/controllers/welcome.php (modified) (1 diff)
-
system/libraries/Pagination.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/application/controllers/welcome.php
r412 r443 8 8 print_r ($db); 9 9 } 10 11 function pagination_example() 12 { 13 // You HAVE TO use $this->pagination when initializing the Pagination library. 14 // This is because the pagination views call $this->pagination->url(). 15 // Problem: what in case your page has multiple pagination areas? Hmm... 16 $this->pagination = new Pagination(array( 17 'base_url' => 'welcome/pagination_example/page/', // page segment doesn't need to be the last one 18 'uri_segment' => 4, // 'uri_label' => 'page' would have the same result 19 'total_items' => 254, // use db count query here of course 20 'items_per_page' => 10, // it may be handy to set defaults for stuff like this in config/pagination.php 21 'style' => 'classic' // pick one from: classic (default), digg, extended, punbb, or add your own! 22 )); 23 24 // Just echoing it is enough to display the links (__toString() rocks!) 25 echo 'Classic style: '.$this->pagination; 26 27 // You can also use the create_links() method and pick a style on the fly if you want 28 echo '<hr />Digg style: '.$this->pagination->create_links('digg'); 29 echo '<hr />Extended style: '.$this->pagination->create_links('extended'); 30 echo '<hr />PunBB style: '.$this->pagination->create_links('punbb'); 31 } 10 32 11 33 } -
trunk/system/libraries/Pagination.php
r413 r443 3 3 class Pagination_Core { 4 4 5 public $base_url ;5 public $base_url = ''; 6 6 public $style = 'classic'; 7 7 public $uri_segment = 3; … … 40 40 } 41 41 42 // Explode the base_url into segments 43 $this->base_url = explode('/', trim($this->base_url, '/')); 44 42 45 // If a uri_label is given, look for the corresponding uri_segment 43 46 if (isset($this->uri_label)) 44 47 { 45 $uri_label_segment = array_search($this->uri_label, Kohana::instance()->uri->segment_array());48 $uri_label_segment = array_search($this->uri_label, $this->base_url); 46 49 47 50 if ($uri_label_segment !== FALSE) 48 51 { 49 $this->uri_segment = $uri_label_segment + 1;52 $this->uri_segment = $uri_label_segment + 2; 50 53 } 51 54 } 52 55 53 56 // Create a generic base_url with {page} placeholder 54 $this->base_url = (isset($this->base_url)) ? $this->base_url : Kohana::instance()->uri->string();55 $this->base_url = explode('/', $this->base_url);56 57 $this->base_url[$this->uri_segment - 1] = '{page}'; 57 58 $this->base_url = implode('/', $this->base_url); … … 89 90 $style = (isset($style)) ? $style : $this->style; 90 91 91 return (string) new View(' views/pagination/'.$style, get_object_vars($this));92 return (string) new View('pagination/'.$style, get_object_vars($this)); 92 93 } 93 94 … … 98 99 99 100 /** 100 * Returns a URLwith the specified page number101 * Returns the base_url with the specified page number 101 102 * 102 103 * @access public … … 106 107 public function url($page = NULL) 107 108 { 108 $page = (int) (isset($page)) ? $ this->current_page : $page;109 $page = (int) (isset($page)) ? $page : $this->current_page; 109 110 110 111 return str_replace('{page}', $page, $this->base_url);
