Changeset 847
- Timestamp:
- 10/18/2007 03:46:48 PM (14 months ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
application/controllers/welcome.php (modified) (1 diff)
-
system/libraries/Pagination.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/application/controllers/welcome.php
r824 r847 169 169 // Problem: what in case your page has multiple pagination areas? Hmm... 170 170 $this->pagination = new Pagination(array( 171 'base_url' => 'welcome/pagination_example/page/', // page segment doesn't need to be the last one172 'uri_segment' => 4, // 'uri_label' => 'page' would have the same result171 // 'base_url' => 'welcome/pagination_example/page/', // base_url will default to current uri 172 'uri_segment' => 'page', // pass a string as uri_segment to trigger former 'label' functionality 173 173 'total_items' => 254, // use db count query here of course 174 174 'items_per_page' => 10, // it may be handy to set defaults for stuff like this in config/pagination.php -
trunk/system/libraries/Pagination.php
r833 r847 25 25 public $style = 'classic'; 26 26 public $uri_segment = 3; 27 public $uri_label;28 27 public $items_per_page = 10; 29 28 … … 46 45 * @return void 47 46 */ 48 public function __construct($ setup= array())47 public function __construct($config = array()) 49 48 { 50 // Load pagination setupvalues51 $ setup = array_merge(Config::load('pagination', FALSE), $setup);49 // Merge all pagination config values 50 $config = array_merge(Config::load('pagination', FALSE), (array) $config); 52 51 53 foreach ($setup as $key => $value) 52 // Assign config values to the object 53 foreach ($config as $key => $value) 54 54 { 55 55 if (property_exists($this, $key)) … … 59 59 } 60 60 61 // Explode the base_url into segments 61 // Set a default base_url if none given via config 62 if ($this->base_url == '') 63 { 64 $this->base_url = (string) Kohana::instance()->uri; 65 } 66 67 // Explode base_url into segments 62 68 $this->base_url = explode('/', trim($this->base_url, '/')); 63 69 64 // If a uri_label is given, look for the corresponding uri_segment65 if (is set($this->uri_label))70 // Convert uri 'label' to corresponding integer if needed 71 if (is_string($this->uri_segment)) 66 72 { 67 $uri_label_segment = array_search($this->uri_label, $this->base_url); 68 69 if ($uri_label_segment !== FALSE) 73 if (($key = array_search($this->uri_segment, $this->base_url)) === FALSE) 70 74 { 71 $this->uri_segment = $uri_label_segment + 2; 75 // If uri 'label' is not found, auto add it to base_url 76 $this->base_url[] = $this->uri_segment; 77 $this->uri_segment = count($this->base_url) + 1; 78 } 79 else 80 { 81 $this->uri_segment = $key + 2; 72 82 } 73 83 } 74 84 75 85 // Create a generic base_url with {page} placeholder 76 86 $this->base_url[$this->uri_segment - 1] = '{page}'; 77 $this->base_url = implode('/', $this->base_url); 78 $this->base_url = url::site($this->base_url); 87 $this->base_url = url::site(implode('/', $this->base_url)); 79 88 80 89 // Core pagination values
