Changeset 847

Show
Ignore:
Timestamp:
10/18/2007 03:46:48 PM (14 months ago)
Author:
Geert
Message:
  • Implementing similar uri_segment 'label' functionality to Pagination library.
  • $uri_label is gone.
Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/application/controllers/welcome.php

    r824 r847  
    169169                // Problem: what in case your page has multiple pagination areas? Hmm... 
    170170                $this->pagination = new Pagination(array( 
    171                         'base_url'       => 'welcome/pagination_example/page/', // page segment doesn't need to be the last one 
    172                         'uri_segment'    => 4, // 'uri_label' => 'page' would have the same result 
     171                        // '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 
    173173                        'total_items'    => 254, // use db count query here of course 
    174174                        '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  
    2525        public $style              = 'classic'; 
    2626        public $uri_segment        = 3; 
    27         public $uri_label; 
    2827        public $items_per_page     = 10; 
    2928         
     
    4645         * @return  void 
    4746         */ 
    48         public function __construct($setup = array()) 
     47        public function __construct($config = array()) 
    4948        { 
    50                 // Load pagination setup values 
    51                 $setup = array_merge(Config::load('pagination', FALSE), $setup); 
     49                // Merge all pagination config values 
     50                $config = array_merge(Config::load('pagination', FALSE), (array) $config); 
    5251                 
    53                 foreach ($setup as $key => $value) 
     52                // Assign config values to the object 
     53                foreach ($config as $key => $value) 
    5454                { 
    5555                        if (property_exists($this, $key)) 
     
    5959                } 
    6060                 
    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 
    6268                $this->base_url = explode('/', trim($this->base_url, '/')); 
    6369 
    64                 // If a uri_label is given, look for the corresponding uri_segment 
    65                 if (isset($this->uri_label)) 
     70                // Convert uri 'label' to corresponding integer if needed 
     71                if (is_string($this->uri_segment)) 
    6672                { 
    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) 
    7074                        { 
    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; 
    7282                        } 
    7383                } 
    74                  
     84 
    7585                // Create a generic base_url with {page} placeholder 
    7686                $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)); 
    7988                 
    8089                // Core pagination values