Course Content
Introduction to CodeIgniter 4
CodeIgniter is an Application Development Framework. CodeIgniter is a popular and powerful MVC (Model-View-Controller) framework that is used to develop web applications. It is a free and Open-source PHP framework.
0/5
MVC (Model-View-Controller)
MVC stands for Model-View-Controller. MVC is an application design model consisting of three interconnected parts. They include the model (data), the view (user interface), and the controller (processes that handle input).
0/6
Sessions
The Session class allows you to maintain a user’s "state" and track their activity while they browse your site.
0/1
URI Routing
There is a one-to-one relationship between a URL string and its corresponding controller class/method.
0/2
Working with Database
Like any other framework, we need to interact with the database very often and CodeIgniter makes this job easy for us. It provides a rich set of functionalities to interact with the database.
0/5
Spreadsheet
PhpSpreadsheet is a PHP library for reading and writing spreadsheet files. Importing Excel and CSV into MySQL help to save the user time and avoid repetitive work.
0/1
CodeIgniter 4
About Lesson

The Session class allows you to maintain a user’s “state” and track their activity while they browse your site.

Session Initialization

To access and initialize the session:

$session = Config\Services::session($config);

Example:

$this->session 	= Config\Services::session();

Add data to the session

A set() method is used to add value to the session. It takes two arguments as a parameter first is session name and the second is session value.

$this->session->set('session_name', 'any_value');

We can also pass an array to the set() method to store values in session.

$data = array(
	'username' 	=> 'infovistar',
	'email' 	=> 'info@infovistar.com',
	'logged_in'	=> TRUE
);
$this->session->set($data);

Fetch data from Session

A get() method is used to get data from the session. It takes the session key name as an argument. For example:

$name = $this->session->get('username');

Remove data from Session

A remove() method is used to remove data from the session. It takes the session key name as an argument. For example:

$this->session->remove('session_name');

If you want to remove more than one value then you can use the same remove() function.

$data = array('username', 'email');
$this->session->remove($data);

Destroying a Session

To clear the current session (for example, during a logout), you may simply use either PHP’s session_destroy() function or the library’s destroy() method. Both will work in the same way:

session_destroy();

// or

$this->session->destroy();

Flashdata

While building a web application, we need to store some data for only one time, and later, we want to remove that data. For example, to display some error message or information message. In CodeIgniter, flashdata will only be available until the next request, and it will get deleted automatically.

Add Flashdata:

$this->session->setFlashdata('item','value');

You can also pass an array to setFlashdata(), in the same manner as set().

$data = array(
'username' => 'infovistar',
'email' => 'info@infovistar.com'
);
$this->session->getFlashdata($data);

Retrieve Flashdata:

$this->session->getFlashdata('item');

Or to get an array with all flashdata, simply omit the key parameter:

$this->session->getFlashdata();