Codeigniter

Understanding Codeigniter

CodeIgniter is a lightweight PHP framework that can be used for free and is open-source. This PHP framework is quite effective for developing websites or applications easily.

Some of the websites built with CodeIgniter are Casio and Nissan.

How CodeIgniter Works

The way CodeIgniter works is quite simple as shown in the following image when a visitor accesses the website via a browser: n” style=”box-sizing: border-box; margins: 0px; padding: 0px; borders: 0px; outline: 0px; font-size: 18px; vertical-align: baseline; background: transparent; max-width: 100%; display: block !important;”>Every time there is a request on the website, it will be directed to the index.php page. Routing will determine the flow of requests from the user. If the requested page is in caching, then routing will perform step 3.If routing redirects to caching, then the page displayed is a page that has been stored in the cache before. If routing points to security, then all data from users will be filtered to improve security before being directed to the controller. The controller will call models, libraries, helpers, and other tools that required for the requested web page. The view will be displayed according to the user’s request. That way, the user can see the web page that is as desired. The web page will be stored in the cache. The goal is to improve website performance because user requests do not need to be directed to the controller again.

CodeIgniter URL Structure

CodeIgniter has a pretty neat URL structure, namely [base-url]/index.php/[class]/[function] For example if you have the URL localhost/learn-codeigniter/index.php/user/add, then the explanation is as follows :

Base-url: localhost/belajar-codeigniter/Class: userFunction: add

In fact, you can also do additional configuration to make the URL simpler. We’ll explain that in the CodeIgniter settings section.

Creating a Website with CodeIgniter

To create a website using CodeIgniter, as a first step you need to do initial configuration. What needs to be done?

1. Creating a Custom Initial View

To make a custom website initial appearance, you can create a file called Homepage.php in the application/controllers folder. Make sure you use a capital letter at the beginning of the file so that the file can be read by CodeIgniter. This file will later become the controller for your start page. After creating the file, make sure the structure looks like this:

After successfully creating the file, you can add the code:

<?php class Homepage extends CI_Controller { public function index() { $this->load->view(‘home’); } }

The explanation of the code above is as follows:

In the Homepage extends CI_Controller class code, you will create a class with the name Homepage. After that, the Homepage class is set with extensions so that it can use the features of the CI_Controller class which can connect the view with the model. Then, you will write the code for the public function index() in the Homepage class so that the commands in the index() can be executed immediately when the Homepage class is accessed. Inside the index() function, you call a view named home using the $this->load->view() command. That’s an explanation of the controller file that has been created. Next, you can create a view to set the view. You can create a file called home.php in the application/views folder. Here’s an example:

After that, you can code below into the home.php file:

!DOCTYPE html> <html> <head> <title>CodeIgniter Start Page</title> </head> <body> <h1>Welcome. This is the Homepage</h1> </body> </html>

Don’t forget to open the routes.php file in the application/config folder, okay? After that, find the code $route[‘default_controller’] and change its contents to the homepage. That way, the code will be like this:

$route[‘default_controller’] = ‘homepage’;

The need for digital IT is needed in daily activities, Bead IT Consultant is the right choice as your partner, visit our website by clicking this link: www.beadgroup.com