Module 6 - Session and Pagination Library
Module 6 - Session and Pagination Library
IT0049
Module 6
Session and Pagination
Library
• To be able to manage session for storing small data.
• To use session in forms and as data references.
Session class should either be initialized in your controller constructors, or it
can be auto-loaded by the system.
$this->load->library('session’);
$_SESSION
// or:
$this->session->userdata();
You can simply assign data to the $_SESSION array, as with any other
variable. Or as a property of $this->session.
For example, assigning a session data with the name “sessdata” should look
something like:
$this->session->sessdata = “value”;
Where $array is an associative array containing your new data.
Here’s an example:
$newdata = array(
'username' => 'johndoe’,
'email' => '[email protected]’,
'logged_in' => TRUE );
$this->session->set_userdata($newdata);
If you want to verify that a session value exists, simply check with isset():
isset($_SESSION['some_name’]);
$this->session->has_userdata('some_name');
Unsetting a value in $_SESSION can be done through unset():
unset($_SESSION['some_name']);
or multiple values:
$this->session->mark_as_flash('item’);
If you want to mark multiple items as flashdata, simply pass the keys as an
array:
$this->session->mark_as_flash(array('item', 'item2'));
To add flashdata:
$_SESSION['item'] = 'value’;
$this->session->mark_as_flash('item’);
However, if you want to be sure that you’re reading “flashdata”, you can also
use the flashdata() method:
$this->session->flashdata('item’);
Or to get an array with all flashdata, simply omit the key parameter:
$this->session->flashdata();
If you find that you need to preserve a flashdata variable through an additional
request, you can do so using the keep_flashdata() method.
To mark an existing item as “tempdata”, simply pass its key and expiry time
(in seconds!) to the mark_as_temp() method:
unset($_SESSION['item']);
Or
$this->session->unset_tempdata('item');
To clear the current session ,you may simply use either
PHP’s session_destroy() function, or the sess_destroy() method.
session_destroy();
// or
$this->session->sess_destroy();
Pagination
Pagination refers to links that allows you to navigate from page to page, like
this:
$config[‘uri_segment’] = 3;
Pagination function automatically determines which segment of your URI contains the page
number.
$config[‘num_links’] = 2;
The number of “digit” links you would like before and after the selected page number.
$config[‘use_page_numbers’] = TRUE;
By default, the URI segment will use the starting index for the items you are paginating.
$config[‘page_query_string’] = TRUE;
By default, the pagination library assume you construct your links something like:
http://example.com/index.php/test/page/20
http://example.com/index.php?c=test&m=page&per_page=20
Adding Enclosing Markup
$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.
Customizing the First Link
$config[‘first_link’] = ‘First’;
The text shown in the “first” link. Setting the value to FALSE will hide this
link.
$config[‘first_tag_open’] = ‘<div>’;
Opening tag for the “first” link.
$config[‘first_tag_close’] = ‘</div>’;
Closing tag for the “first” link.
Customizing the Last Link
$config[‘last_link’] = ‘Last’;
The text shown in the “last” link. Setting the value to FALSE will hide this
link.
$config[‘last_tag_open’] = ‘<div>’;
Opening tag for the “last” link.
$config[‘last_tag_close’] = ‘</div>’;
Closing tag for the “last” link.
Customizing the “Next” Link
$config[‘next_link’] = ‘>’;
The text shown in the “next” page link. Setting the value to FALSE will hide
this link.
$config[‘next_tag_open’] = ‘<div>’;
Opening tag for the “next” link.
$config[‘next_tag_close’] = ‘</div>’;
Closing tag for the “next” link.
Customizing the “Previous” Link
$config[‘prev_link’] = ‘<’;
The text shown in the “previous” page link. Setting the value to FALSE will
hide this link.
$config[‘prev_tag_open’] = ‘<div>’;
Opening tag for the “previous” link.
$config[‘prev_tag_close’] = ‘</div>’;
Closing tag for the “previous” link.
Customizing the “Current Page” Link
$config[‘cur_tag_open’] = ‘<b>’;
Opening tag for the “current” link.
$config[‘cur_tag_close’] = ‘</b>’;
Closing tag for the “current” link.
Customizing the “Digit" Link
$config[‘num_tag_open’] = ‘<div>’;
Opening tag for the “digit” link.
$config[‘num_tag_close’] = ‘</div>’;
Closing tag for the “digit” link.
Hiding the Pages
$config['display_pages'] = FALSE;
If you only want “next” and “previous” links displayed.