How to paging with CodeIgniter (1.)

On 27. Február 2011, in Programming, by radypala

Welcome at my first mini-serial. I will introduce you how to create a simple, easy pager in CodeIgniter. I suppose you have successfully instaled the framework. So lets create the config file in config directory. The name of the file will be the same as the name of Library, which we wil be use – pagination. The path of the file should be application/config/pagination.php.  You can find it also in the User Guide, but i did not find created file with all comments like another config file. For example, next time you will not have to create the file or look for something in UserGuide.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Pagination
|--------------------------------------------------------------------------
| This file sets config values for library Pagination.
| It is loaded automatically, so youu must not load it manually.
*/
/*
|--------------------------------------------------------------------------
| Customizing the Pagination
|--------------------------------------------------------------------------
|  $config['page_query_string'] = TRUE;
|  By default, the pagination library assume you are using URI Segments, and constructs your links something like
|   http://example.com/index.php/test/page/20
|
| If you have $config['enable_query_strings'] set to TRUE your links will automatically be re-written using Query Strings.
| This option can also be explictly set. Using $config['page_query_string'] set to TRUE, the pagination link will become.
|   http://example.com/index.php?c=test&amp;m=page&amp;per_page=20
|
| Note that "per_page" is the default query string passed, however can be configured using
| $config['query_string_segment'] = 'your_string'
|
*/
$config['page_query_string'] = TRUE;
/*
| The pagination function automatically determines which segment of your URI contains the page number.
| If you need something different you can specify it.
|
| $config['uri_segment'] = 3;
*/
/*
| The number of "digit" links you would like before and after the selected page number.
| For example, the number 2 will place two digits on either side, as in the example links at the very top of this page.
|
| $config['num_links'] = 2;
*/
$config['num_links'] = 2;
/*
|--------------------------------------------------------------------------
| Adding Enclosing Markup
|--------------------------------------------------------------------------
| If you would like to surround the entire pagination with some markup you can do it with these two prefs:
| $config['full_tag_open'] = '<p>';   //The opening tag placed on the left side of the entire result.
| $config['full_tag_close'] = '</p>'; //The closing tag placed on the right side of the entire result.
*/
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
/*
|--------------------------------------------------------------------------
| Customizing the First Link
|--------------------------------------------------------------------------
| The opening tag for the "first" link:
|   $config['first_tag_open'] = '<div>';
|
| The closing tag for the "first" link:
|   $config['first_tag_close'] = '</div>';
|
| The text you would like shown in the "first" link on the left.
| If you do not want this link rendered, you can set its value to FALSE.
| $config['first_link'] = 'First';
*/
$config['first_link'] = 'Prvá stránka';
/*
|--------------------------------------------------------------------------
| Customizing the last Link
|--------------------------------------------------------------------------
| The opening tag for the "last" link:
|   $config['last_tag_open'] = '<div>';
|
| The closing tag for the "last" link:
|   $config['last_tag_close'] = '</div>';
|
| The text you would like shown in the "last" link on the left.
| If you do not want this link rendered, you can set its value to FALSE.
| $config['first_link'] = 'Last';
*/
$config['last_link'] = 'Posledná';
/*
|--------------------------------------------------------------------------
| Customizing the Next Link
|--------------------------------------------------------------------------
|
| $config['next_tag_open'] = '<div>';
| The opening tag for the "next" link.
|
| $config['next_tag_close'] = '</div>';
| The closing tag for the "next" link.
|
| The text you would like shown in the "next" page link.
| If you do not want this link rendered, you can set its value to FALSE.
| $config['next_link'] = 'Next';
*/
$config['next_link'] = 'Nasledujúca';
/*
|--------------------------------------------------------------------------
| Customizing the Previous Link
|--------------------------------------------------------------------------
| $config['prev_tag_open'] = '<div>';
| The opening tag for the "previous" link.
|
| $config['prev_tag_close'] = '</div>';
| The closing tag for the "previous" link.
|
| The text you would like shown in the "prev" page link.
| If you do not want this link rendered, you can set its value to FALSE.
| $config['next_link'] = 'Previous';
*/
$config['prev_link'] = 'Predchádzajúca';
/*
|--------------------------------------------------------------------------
| Customizing the "Current Page" Link
|--------------------------------------------------------------------------
|  $config['cur_tag_open'] = '<b>';
| The opening tag for the "current" link.
|
| $config['cur_tag_close'] = '</b>';
| The closing tag for the "current" link.
*/
$config['cur_tag_open'] = '<b>';
$config['cur_tag_close'] = '</b>';
/*
|--------------------------------------------------------------------------
| Customizing the "Digit" Link
|--------------------------------------------------------------------------
| $config['num_tag_open'] = '<div>';
| The opening tag for the "digit" link.
|
| $config['num_tag_close'] = '</div>';
| The closing tag for the "digit" link.
*/
/*
| If you wanted to not list the specific pages (for example, you only want "next" and "previous" links),
| you can suppress their rendering by adding:
| $config['display_pages'] = FALSE;
*/
?>

Now we have config file. You can see, that i have not thinked about multi-language support. But it does not matter, this is just a start. After we will create the the simple MVC structure for example of using, i will show you how to do it in more languages.

Enjoy it!

 

Prvý článok

On 16. Október 2010, in Nezaradené, by radypala

Zdravím všetkých (ne)priaznivcov,

dnešným nudným večerom som sa rozhodol založiť si internetový “denníček”, aj keď práve to nie je úplne “in” v dnešnom roku, keď každý kto nemá Facebook ako keby neexistoval. Dúfam že pritiahnem čo najviac záujemcov a nie je podstatné, či aj nepriaznivcov, lebo aj zlá reklama je reklama. Dôležité je, aby… tí inteligentnejším dôjde o čo mi ide. :-)