Codeigniter : The Intro
Let’s start with Codeigniter
- Why use Framework?
Frameworks have several advantages
The framework helps us to be more productive and protect us from low-level error such as preventing SQL injection attack.
With the framework, we can improve the design and make our code much easier to read, maintain and unit test. The framework is a layered structure.
The framework is generally more comprehensive than a protocol and more prescriptive than a structure.
Codeigniter is an application development framework, which can be used to develop websites using PHP. Codeigniter has rich set of functionality, which helps us to increase the speed of website development work.
It has rich set of libraries and helpers. If we are developing a website from scratch it saves lots of time. A website built in CodeIgniter is secure too.
CodeIgniter is one of the most popular PHP frameworks and it follows the MVC pattern. Web Developer can be able to build full-featured rich web applications with CodeIgniter.
- Codeigniter Features
Some of the important features of CodeIgniter are listed below −
- Model-View-Controller Based System
- Extremely Light Weight
- It has rich set of active record database classes.
- Query Builder Database Support
- Form and Data Validation
- Security and XSS Filtering
- Session Management
- Email Sending Class. Supports Attachments, HTML/Text email, multiple protocols (Sendmail, SMTP, and Mail) and more.
- File Uploading Class
- Zip Encoding Class
- Large library of “helper” functions
MVC stands for Model View Controller. The model view controller model is the most used pattern for today’ web applications. At present, there is more than a dozen PHP framework based on MVC model. The MVC model separates an application in 3 modules: Model, View, and Controller.
Model is PHP classes that are responsible for managing the data. It contains all database operations.
Loading a model:
To use model we can load that within our controller method
To load a model you will use the following method:
The View is responsible for displaying the data provided by the model in a specific format. Views are never called directly they must be loaded by Controller.
Loading a view
Where name is the name of your view file.
The Controller handles the model and view layers to work together.
Controller class name must start with uppercase letters. When url is not present codeigniter loads default controller which is in route.php file
ex.$route[‘default_controller’] = ‘blog’;
Controller is glue between model and view.
Libraries are the classes in procedural language. Before using the classes we have to instantiate those in our project.
Ex: Session, codeigniterDatabase, Form –validation
Helpers are collection of function in a particular caCodeIgniter we have URL helper, TEXT helper, FORM helper, COOKIE helper and FILE helper.
Each helper function performs one specific task.
Loading a helper:
Helpers are stored in your system/helpers, or application/helpers directory. CodeIgniter will look first in your application/helpers directory. If the directory does not exist or the specified helper is not located there CI will instead look in your global system/helpers folder.
Images: MVC model