In this post I cover the scenario where you’ve been asked to work on a CodeIgniter website, and you’ve only got 10 minutes to find out how it works! I’ll be brief but I’ll cover
- What is CodeIniter?
- What is MVC?
- CodeIgniter structure and where to find js, css and images
- How to find the page you want to edit
- Other possibilities
- Where to go next
What is CodeIgniter?
CodeIgniter is a powerful, lightweight PHP MVC framework. It makes it quick and easy to build web sites and applications.
What is MVC?
MVC is a software architecture and stands for Model-View-Controller. It enables the separation of presentation code, logic and data.
Models – You want some data? The model deals with that.
Views – This is where you put your HTML and presentation code.
Controllers – Tell you where to go, talk to views and models, and are generally in charge of what happens.
CodeIgniter structure and where to find js, css and images
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css" />
The very useful base_url() is set in application/config/config.php
The Models, Views and Controllers are found in
Here’s a possible folder structure.
NB. The application and system folders may have been renamed and moved (to enhance security). To find out where they are look in index.php for $system_path and $application_folder.
How to find the page you want to edit
CodeIngiter URLs are made up of segments, which tell you which Controller to look at. The Controller then tells you which view to look at. It works like this:
(or example.com/index.php/controller/function/ID )
- controller segment tells you which controller to look at
- function segment tells you which function within that controller (optional)
- ID segment represents variables that are passed to the function (optional)
If there’s no function segment, look for the index function.
If there’s no controller segment, you need to find the default controller. Look in application/config/routes.php and find something like
$route['default_controller'] = "welcome";
This means that application/controllers/welcome.php is the default controller.
So, you’ve found the relevant function, now you need to find the view. Look for something like this:
This loads the view called page1. Look for application/views/page1.php. Et voila, here is the presentation code.
If the site doesn’t conform to what I’ve described above, there may be some routing going on. See the CodeIgniter user guide on URI routing for more details on this.
Where to go next
One of the things I love about CodeIgniter is it’s really well documented and has a great community behind it. Check out the CodeIgniter User Guide.