×

What is CodeIgniter, and how does it work?

thumb_12_CodeIgniter-Main-Image.png

Akash Limbani
2019-02-08

 

What is CodeIgniter?

CodeIgniter is a free, open-source, easy-to-use, object-oriented PHP web application framework, providing a ready-to-use library to use with your own PHP applications. For example, there is a Database API to make it easier and more convenient to execute SQL queries, such as SELECT, UPDATE, DELETE, INSERT, etc., without having to create a lot of repetitive code yourself. This is how an application framework is useful in application development.

CodeIgniter is object-oriented

Using CodeIgniter requiring knowledge of using the object-oriented programming technique in order to be able to use CodeIgniter effectively, and to understand what happens when you are using certain features in CodeIgniter.

But, what is object-oriented programming?

It’s quite difficult to explain object-oriented programming because from a conceptual point of view, it is difficult to understand. However, the main purpose of object-oriented programming is to make application development easier, especially as applications become bigger, with large structures. Object-oriented programming allows application code and logic to be easier to understand, structured and coherently in place, making it easier to develop and extend your application’s features and functionality. With procedural programming (which is merely standard code executed line-by-line with the use of functions as a container for code that help prevent repetitiveness and “reinventing the wheel”), applications can become a mess if they aren’t developed in a way where everything is well laid out, coherent and structured, and can be more difficult to extend and add new features and functionality to your applications later on. With object-oriented programming, in a way, you are forced to be coherent and have your code structured correctly.

Classes and Methods

What are classes and methods? These are the first concepts you’ll be introduced to if you are learning object-oriented programming from most books or online resources. Say you’re creating a framework. You’ll have different classes for different parts of your framework. One being a “Database Class”, one being an “E-mail Class”, and so forth. Of course, in this case, the Database Class is like the CodeIgniter Database Class, providing a set of ready-made methods for you to use so you don’t have to create them yourself in order to execute certain application logic, such as inserting, updating and removing database records quickly, without having to “reinvent the wheel”.

The methods are what contain the application logic, and the class merely holds many related methods together. And this is exactly how your applications would work with the use of the object-oriented programming techniques.

How does CodeIgniter work?

CodeIgniter has a very extensive user guide, which is much better than documentation on some other frameworks, such as CakePHP (which is another PHP framework).

CodeIgniter has classes and helpers.

Classes

Classes contain a collection of methods and properties (properties are essentially variables in an object-oriented context).

For example, here is an example using the Database library within CodeIgniter:

$this->db->get(‘users’,$data);

In any application you make using CodeIgniter, your own classes inherit (or extends) the CodeIgniter class, and so this is why the $this variable is used, which refers to the current class/object. So to call another method within your class, you would use $this->method_name().

Helpers

Helpers contain ordinary PHP functions. Such as the Form Helper.

Other interesting features of CodeIgniter

While this is by no means unique to CodeIgniter, and other web application frameworks use this approach to application development, CodeIgniter primarily uses the Model, View, Controller (MVC) approach to application design and development. It essentially separates application logic from the application design/view. The application logic is the Controller, whereas the application design/view is the View. The Model is for database interactions. There are more complex scenarios where the MVC approach is used, but for basic to intermediate CodeIgniter applications, the Model would contain database interactivity logic of sorts.

Active Record

When you saw an example of using the Database Class above, that code is actually part of the Active Record Class that is part of the Database library.

Active Record is where your work can be shortened by providing an easy and convenient way to execute certain SQL queries without having to write out the entire SQL query yourself. Active Record essentially allows information to be updated, retrieved, added and removed conveniently.

More information on CodeIgniter

The CodeIgniter framework works on all of our shared and reseller servers, and can be installed on pretty much any server with PHP installed. As of writing, CodeIgniter requires PHP version 5.1.6 or higher and obviously a database will be required for any database-driven PHP application (as of writing, MySQL 4.1 or higher). CodeIgniter also supports PostgreSQL, Oracle, SQLite and ODBC.

Contact Us


+91-2652320199

1C Satyam Appartment,
Above Trinetra,
Vishwas Colony,
Alkapuri,
Vadodara, Gujarat 390005