admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
| 2 | <html>
|
| 3 | <head>
|
| 4 |
|
| 5 | <title>Code Igniter User Guide</title>
|
| 6 |
|
| 7 | <style type='text/css' media='all'>@import url('../userguide.css');</style>
|
| 8 | <link rel='stylesheet' type='text/css' media='all' href='../userguide.css' />
|
| 9 |
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 10 | <script type="text/javascript" src="../nav/nav.js"></script>
|
admin | 2296fc3 | 2006-09-27 21:07:02 +0000 | [diff] [blame] | 11 | <script type="text/javascript" src="../nav/prototype.lite.js"></script>
|
admin | 17a890d | 2006-09-27 20:42:42 +0000 | [diff] [blame] | 12 | <script type="text/javascript" src="../nav/moo.fx.js"></script>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 13 | <script type="text/javascript">
|
| 14 | window.onload = function() {
|
| 15 | myHeight = new fx.Height('nav', {duration: 400});
|
| 16 | myHeight.hide();
|
| 17 | }
|
| 18 | </script>
|
| 19 |
|
| 20 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
| 21 | <meta http-equiv='expires' content='-1' />
|
| 22 | <meta http-equiv= 'pragma' content='no-cache' />
|
| 23 | <meta name='robots' content='all' />
|
| 24 | <meta name='author' content='Rick Ellis' />
|
| 25 | <meta name='description' content='Code Igniter User Guide' />
|
| 26 |
|
| 27 | </head>
|
| 28 | <body>
|
| 29 |
|
| 30 | <!-- START NAVIGATION -->
|
| 31 | <div id="nav"><div id="nav_inner"><script type="text/javascript">create_menu('../');</script></div></div>
|
| 32 | <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle.jpg" width="153" height="44" border="0" title="Toggle Table of Contents" alt="Toggle Table of Contents" /></a></div>
|
| 33 | <div id="masthead">
|
| 34 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 35 | <tr>
|
admin | 10c3f41 | 2006-10-08 07:21:12 +0000 | [diff] [blame] | 36 | <td><h1>Code Igniter User Guide Version 1.5.0b1</h1></td>
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 37 | <td id="breadcrumb_right"><a href="../toc.html">Full Table of Contents</a></td>
|
| 38 | </tr>
|
| 39 | </table>
|
| 40 | </div>
|
| 41 | <!-- END NAVIGATION -->
|
| 42 |
|
| 43 |
|
| 44 | <!-- START BREADCRUMB -->
|
| 45 | <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
|
| 46 | <tr>
|
| 47 | <td id="breadcrumb">
|
| 48 | <a href="http://www.codeigniter.com/">Code Igniter Home</a> ›
|
| 49 | <a href="../index.html">User Guide Home</a> ›
|
| 50 | Pagination Class
|
| 51 | </td>
|
| 52 | <td id="searchbox"><form method="get" action="http://www.google.com/search"><input type="hidden" name="as_sitesearch" id="as_sitesearch" value="www.codeigniter.com/user_guide/" />Search User Guide <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" /> <input type="submit" class="submit" name="sa" value="Go" /></form></td>
|
| 53 | </tr>
|
| 54 | </table>
|
| 55 | <!-- END BREADCRUMB -->
|
| 56 |
|
| 57 | <br clear="all" />
|
| 58 |
|
| 59 |
|
| 60 | <!-- START CONTENT -->
|
| 61 | <div id="content">
|
| 62 |
|
| 63 |
|
| 64 | <h1>Pagination Class</h1>
|
| 65 |
|
| 66 | <p>Code Igniter's Pagination class is very easy to use, and it is 100% customizable, ether dynamically or via stored preferences.</p>
|
| 67 |
|
| 68 | <p>If you are not familiar with the term "pagination", it refers to links that allows you to navigate from page to page, like this:</p>
|
| 69 |
|
| 70 | <code><a href="#">« First</a> <a href="#"><</a> <a href="#">1</a> <a href="#">2</a> <b>3</b> <a href="#">4</a> <a href="#">5</a> <a href="#">></a> <a href="#">Last »</a></code>
|
| 71 |
|
| 72 | <h2>Example</h2>
|
| 73 |
|
| 74 | <p>Here is a simple example showing how to create pagination in one of your <a href="../general/controllers.html">controller</a> functions:</p>
|
| 75 |
|
| 76 | <code>
|
| 77 | $this->load->library('pagination');<br /><br />
|
| 78 | $config['base_url'] = 'http://www.your-site.com/index.php/test/page/';<br />
|
| 79 | $config['total_rows'] = '200';<br />
|
| 80 | $config['per_page'] = '20';
|
| 81 | <br /><br />
|
| 82 | $this->pagination->initialize($config);
|
| 83 |
|
| 84 | <br /><br />
|
| 85 | echo $this->pagination->create_links();</code>
|
| 86 |
|
| 87 | <h3>Notes:</h3>
|
| 88 |
|
| 89 | <p>The <var>$config</var> array contains your configuration variables. It is passed to the <dfn>$this->pagination->initialize</dfn> function as shown above. Although there are some twenty items you can configure, at
|
| 90 | minimum you need the three shown. Here is a description of what those items represent:</p>
|
| 91 |
|
| 92 | <ul>
|
| 93 | <li><strong>base_url</strong> This is the full URL to the controller class/function containing your pagination. In the example
|
admin | 141808a | 2006-08-27 01:52:51 +0000 | [diff] [blame] | 94 | above, it is pointing to a controller called "Test" and a function called "page". Keep in mind that you can
|
admin | b0dd10f | 2006-08-25 17:25:49 +0000 | [diff] [blame] | 95 | <a href="../general/routing.html">re-route your URI</a> if you need a different structure.</li>
|
| 96 | <li><strong>total_rows</strong> This number represents the total rows in the result set you are creating pagination for.
|
| 97 | Typically this number will be the total rows that your database query returned.
|
| 98 | </li>
|
| 99 | <li><strong>per_page</strong> The number of items you intend to show per page. In the above example, you would be showing 20 items per page.</li>
|
| 100 | </ul>
|
| 101 |
|
| 102 | <p>The <var>create_links()</var> function returns an empty string when there is no pagination to show.
|
| 103 |
|
| 104 |
|
| 105 | <h3>Setting preferences in a config file</h3>
|
| 106 |
|
| 107 | <p>If you prefer not to set preferences using the above method, you can instead put them into a config file.
|
| 108 | Simply create a new file called the <var>pagination.php</var>, add the <var>$config</var>
|
| 109 | array in that file. Then save the file in: <var>config/pagination.php</var> and it will be used automatically. You
|
| 110 | will NOT need to use the <dfn>$this->pagination->initialize</dfn> function if you save your preferences in a config file.</p>
|
| 111 |
|
| 112 |
|
| 113 | <h2>Customizing the Pagination</h2>
|
| 114 |
|
| 115 | <p>The following is a list of all the preferences you can pass to the initialization function to tailor the display.</p>
|
| 116 |
|
| 117 |
|
| 118 | <h4>$config['uri_segment'] = 3;</h4>
|
| 119 |
|
| 120 | <p>The pagination function automatically determines which segment of your URI contains the page number. If you need
|
| 121 | something different you can specify it.</p>
|
| 122 |
|
| 123 | <h4>$config['num_links'] = 2;</h4>
|
| 124 |
|
| 125 | <p>The number of "digit" links you would like before and after the the selected page number. For example, the number 2
|
| 126 | will place two digits on either side, as in the example links at the very top of this page.</p>
|
| 127 |
|
| 128 | <h2>Adding Enclosing Markup</h2>
|
| 129 |
|
| 130 | <p>If you would like to surround the entire pagination with some markup you can do it with these two prefs:</p>
|
| 131 |
|
| 132 | <h4>$config['full_tag_open'] = '<p>';</h4>
|
| 133 | <p>The opening tag placed on the left side of the entire result.</p>
|
| 134 |
|
| 135 | <h4>$config['full_tag_close'] = '</p>';</h4>
|
| 136 | <p>The closing tag placed on the right side of the entire result.</p>
|
| 137 |
|
| 138 |
|
| 139 | <h2>Customizing the First Link</h2>
|
| 140 |
|
| 141 | <h4>$config['first_link'] = 'First';</h4>
|
| 142 | <p>The text you would like shown in the "first" link on the left.</p>
|
| 143 |
|
| 144 | <h4>$config['first_tag_open'] = '<div>';</h4>
|
| 145 | <p>The opening tag for the "first" link.</p>
|
| 146 |
|
| 147 | <h4>$config['first_tag_close'] = '</div>';</h4>
|
| 148 | <p>The closing tag for the "first" link.</p>
|
| 149 |
|
| 150 | <h2>Customizing the Last Link</h2>
|
| 151 |
|
| 152 | <h4>$config['last_link'] = 'Last';</h4>
|
| 153 | <p>The text you would like shown in the "last" link on the right.</p>
|
| 154 |
|
| 155 | <h4>$config['last_tag_open'] = '<div>';</h4>
|
| 156 | <p>The opening tag for the "last" link.</p>
|
| 157 |
|
| 158 | <h4>$config['last_tag_close'] = '</div>';</h4>
|
| 159 | <p>The closing tag for the "last" link.</p>
|
| 160 |
|
| 161 | <h2>Customizing the "Next" Link</h2>
|
| 162 |
|
| 163 | <h4>$config['next_link'] = '&gt';</h4>
|
| 164 | <p>The text you would like shown in the "next" page link.</p>
|
| 165 |
|
| 166 | <h4>$config['next_tag_open'] = '<div>';</h4>
|
| 167 | <p>The opening tag for the "next" link.</p>
|
| 168 |
|
| 169 | <h4>$config['next_tag_close'] = '</div>';</h4>
|
| 170 | <p>The closing tag for the "next" link.</p>
|
| 171 |
|
| 172 | <h2>Customizing the "Previous" Link</h2>
|
| 173 |
|
| 174 | <h4>$config['prev_link'] = '&lt';</h4>
|
| 175 | <p>The text you would like shown in the "previous" page link.</p>
|
| 176 |
|
| 177 | <h4>$config['prev_tag_open'] = '<div>';</h4>
|
| 178 | <p>The opening tag for the "previous" link.</p>
|
| 179 |
|
| 180 | <h4>$config['prev_tag_close'] = '</div>';</h4>
|
| 181 | <p>The closing tag for the "previous" link.</p>
|
| 182 |
|
| 183 | <h2>Customizing the "Current Page" Link</h2>
|
| 184 |
|
| 185 | <h4>$config['cur_tag_open'] = '<b>';</h4>
|
| 186 | <p>The opening tag for the "current" link.</p>
|
| 187 |
|
| 188 | <h4>$config['cur_tag_close'] = '</b>';</h4>
|
| 189 | <p>The closing tag for the "current" link.</p>
|
| 190 |
|
| 191 |
|
| 192 | <h2>Customizing the "Digit" Link</h2>
|
| 193 |
|
| 194 | <h4>$config['num_tag_open'] = '<div>';</h4>
|
| 195 | <p>The opening tag for the "digit" link.</p>
|
| 196 |
|
| 197 | <h4>$config['num_tag_close'] = '</div>';</h4>
|
| 198 | <p>The closing tag for the "digit" link.</p>
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 | </div>
|
| 203 | <!-- END CONTENT -->
|
| 204 |
|
| 205 |
|
| 206 | <div id="footer">
|
| 207 | <p>
|
| 208 | Previous Topic: <a href="output.html">Output Class</a>
|
| 209 | ·
|
| 210 | <a href="#top">Top of Page</a> ·
|
| 211 | <a href="../index.html">User Guide Home</a> ·
|
| 212 | Next Topic: <a href="sessions.html">Session Class</a>
|
| 213 | <p>
|
| 214 | <p><a href="http://www.codeigniter.com">Code Igniter</a> · Copyright © 2006 · <a href="http://www.pmachine.com">pMachine, Inc.</a></p>
|
| 215 | </div>
|
| 216 |
|
| 217 | </body>
|
| 218 | </html> |