Changeset 2097

Show
Ignore:
Timestamp:
02/21/2008 11:02:24 AM (8 months ago)
Author:
Geert
Message:
  • Pagination API change: create_links() has been renamed to render(). It is shorter, more consistent and also describes better what the method actually does.
  • Implemented #419: auto_hide option. Setting it to TRUE will hide all pagination stuff if there are only 1 or 0 pages in total.
Location:
trunk
Files:
2 modified

Legend:

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

    r2088 r2097  
    261261                echo 'Classic style: '.$pagination; 
    262262 
    263                 // You can also use the create_links() method and pick a style on the fly if you want 
    264                 echo '<hr />Digg style:     '.$pagination->create_links('digg'); 
    265                 echo '<hr />Extended style: '.$pagination->create_links('extended'); 
    266                 echo '<hr />PunBB style:    '.$pagination->create_links('punbb'); 
     263                // You can also use the render() method and pick a style on the fly if you want 
     264                echo '<hr />Digg style:     '.$pagination->render('digg'); 
     265                echo '<hr />Extended style: '.$pagination->render('extended'); 
     266                echo '<hr />PunBB style:    '.$pagination->render('punbb'); 
    267267                echo 'done in {execution_time} seconds'; 
    268268        } 
  • trunk/system/libraries/Pagination.php

    r2029 r2097  
    1919        protected $items_per_page = 10; 
    2020        protected $total_items    = 0; 
     21        protected $auto_hide      = FALSE; 
    2122 
    2223        // Automatically generated values 
     
    117118         * @return  string  pagination html 
    118119         */ 
    119         public function create_links($style = NULL) 
     120        public function render($style = NULL) 
    120121        { 
    121                 $style = (isset($style)) ? $style : $this->style; 
    122                 $view = new View($this->directory.$style, get_object_vars($this)); 
    123                 return $view->render(); 
     122                // Hide single page pagination 
     123                if ($this->auto_hide == TRUE AND $this->total_pages <= 1) 
     124                        return ''; 
     125 
     126                if ($style === NULL) 
     127                { 
     128                        // Use default style 
     129                        $style = $this->style; 
     130                } 
     131 
     132                // Return rendered pagination view 
     133                return View::factory($this->directory.$style, get_object_vars($this))->render(); 
    124134        } 
    125135 
     
    131141        public function __toString() 
    132142        { 
    133                 return $this->create_links(); 
     143                return $this->render(); 
    134144        } 
    135145