Show
Ignore:
Timestamp:
12/14/2007 03:27:07 PM (11 months ago)
Author:
Geert
Message:

Pagination library update:

  • Fixed bug that made it impossible to change uri_segment via initialize() without explicitely passing base_url again. (Also see: http://forum.kohanaphp.com/index.php/topic,389.0.html)
  • The generic url (used in the pagination style views) is now stored in $url. Shorter, keeps your views a bit cleaner and $base_url is reserved to be set by user.
  • Made $base_url, $directory, $style and $uri_segment private. They should not be available in pagination views.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/Pagination.php

    r1522 r1535  
    1111 
    1212        // Config values 
    13         protected $base_url       = ''; 
    14         protected $directory      = 'pagination'; 
    15         protected $style          = 'classic'; 
    16         protected $uri_segment    = 3; 
     13        private  $base_url       = ''; 
     14        private  $directory      = 'pagination'; 
     15        private  $style          = 'classic'; 
     16        private  $uri_segment    = 3; 
    1717        protected $items_per_page = 10; 
     18        protected $total_items    = 0; 
    1819 
    19         // Automatically calculated values 
     20        // Automatically generated values 
     21        protected $url; 
    2022        protected $current_page; 
    2123        protected $total_pages; 
    22         protected $total_items; 
    2324        protected $current_first_item; 
    2425        protected $current_last_item; 
     
    6667                $this->directory = trim($this->directory, '/').'/'; 
    6768 
    68                 // Don't bother about full base_urls 
    69                 if (strpos($this->base_url, '://') === FALSE) 
     69                // Start building a generic URL 
     70                $this->url = ($this->base_url == '') ? Router::$segments : $this->url = explode('/', trim($this->base_url, '/')); 
     71 
     72                // Convert uri 'label' to corresponding integer if needed 
     73                if (is_string($this->uri_segment)) 
    7074                { 
    71                         // Default base_url 
    72                         if ($this->base_url == '') 
     75                        if (($key = array_search($this->uri_segment, $this->url)) === FALSE) 
    7376                        { 
    74                                 $this->base_url = url::current(); 
     77                                // If uri 'label' is not found, auto add it to base_url 
     78                                $this->url[] = $this->uri_segment; 
     79                                $this->uri_segment = count($this->url) + 1; 
    7580                        } 
    76  
    77                         // Explode base_url into segments 
    78                         $this->base_url = explode('/', trim($this->base_url, '/')); 
    79  
    80                         // Convert uri 'label' to corresponding integer if needed 
    81                         if (is_string($this->uri_segment)) 
     81                        else 
    8282                        { 
    83                                 if (($key = array_search($this->uri_segment, $this->base_url)) === FALSE) 
    84                                 { 
    85                                         // If uri 'label' is not found, auto add it to base_url 
    86                                         $this->base_url[] = $this->uri_segment; 
    87                                         $this->uri_segment = count($this->base_url) + 1; 
    88                                 } 
    89                                 else 
    90                                 { 
    91                                         $this->uri_segment = $key + 2; 
    92                                 } 
     83                                $this->uri_segment = $key + 2; 
    9384                        } 
    94  
    95                         // Create a generic base_url including query string and a {page} placeholder 
    96                         $this->base_url[$this->uri_segment - 1] = '{page}'; 
    97                         $this->base_url = url::site(implode('/', $this->base_url)).Router::$query_string; 
    9885                } 
     86         
     87                // Create a generic URL with query string and {page} number placeholder 
     88                $this->url[$this->uri_segment - 1] = '{page}'; 
     89                $this->url = url::site(implode('/', $this->url)).Router::$query_string; 
    9990 
    10091                // Core pagination values