Changeset 443

Show
Ignore:
Timestamp:
08/29/2007 12:02:58 PM (14 months ago)
Author:
Geert
Message:
  • More bug fixes
  • I added a temporary pagination example to the welcome controller. Go check it out!
Location:
trunk
Files:
2 modified

Legend:

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

    r412 r443  
    88                print_r ($db); 
    99        } 
     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        } 
    1032 
    1133} 
  • trunk/system/libraries/Pagination.php

    r413 r443  
    33class Pagination_Core { 
    44         
    5         public $base_url; 
     5        public $base_url           = ''; 
    66        public $style              = 'classic'; 
    77        public $uri_segment        = 3; 
     
    4040                } 
    4141                 
     42                // Explode the base_url into segments 
     43                $this->base_url = explode('/', trim($this->base_url, '/')); 
     44 
    4245                // If a uri_label is given, look for the corresponding uri_segment 
    4346                if (isset($this->uri_label)) 
    4447                { 
    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); 
    4649                         
    4750                        if ($uri_label_segment !== FALSE) 
    4851                        { 
    49                                 $this->uri_segment = $uri_label_segment + 1; 
     52                                $this->uri_segment = $uri_label_segment + 2; 
    5053                        } 
    5154                } 
    5255                 
    5356                // 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); 
    5657                $this->base_url[$this->uri_segment - 1] = '{page}'; 
    5758                $this->base_url = implode('/', $this->base_url); 
     
    8990                $style = (isset($style)) ? $style : $this->style; 
    9091                 
    91                 return (string) new View('views/pagination/'.$style, get_object_vars($this)); 
     92                return (string) new View('pagination/'.$style, get_object_vars($this)); 
    9293        } 
    9394         
     
    9899 
    99100        /** 
    100          * Returns a URL with the specified page number 
     101         * Returns the base_url with the specified page number 
    101102         * 
    102103         * @access  public 
     
    106107        public function url($page = NULL) 
    107108        { 
    108                 $page = (int) (isset($page)) ? $this->current_page : $page; 
     109                $page = (int) (isset($page)) ? $page : $this->current_page; 
    109110                 
    110111                return str_replace('{page}', $page, $this->base_url);