Codeigniter Tutorials CodeIgniter Directory Structure explanation

CodeIgniter Directory Structure explanation

CodeIgniter Directory Structure explaination by techbriefers

Before starting to code using CodeIgniter, you should understand its directory structure. You should understand this structure to work efficiently with CodeIgniter. CodeIgniter Directory Structure is very simple and easy to understand for newbies. This structure contains many folders and files. However, the structure is categories into 3 directories as I am mentioning below.

  • Application
  • System
  • User_guide
CodeIgniter File Structure by Techbriefers

Application directory in CodeIgniter

This folder is the core use for developers. This application folder, like its name, is the container of all of the codes that you will do to build your project. Anything you will be doing and any file you will be creating will reside in this folder and its subfolders. Below is a list of the sub-directories in application folder – in CodeIgniter directory structure.

#1 Cache folder in CodeIgniter

As I explained in the previous topic. If the cache is present then the browser will be provided that cached result. Those cached pages of the application are stored in this folder. which increases the overall performance of the project or website.

#2 Config Directory in CodeIgniter Directory Structure

Config folder contains files containing the configuration data of the application. It has many files which I am listing below with their respective explanation.

autoload.php

In this file, you need to configure names of drivers, helpers, config files, models and languages. These files are those you need to load (call) automatically with the framework initialization.

Example:  $autoload['model'] = array(‘userModel, adminModel’);

config.php

In this file, you can set up various core configurations for your application. Like: Base URL, index page, character set, etc. However, you must configure your base URL and can start working. Others are not mandatory.

constants.php

In this file, there are a few predefined constants present. You can define you required constants in this file. I would suggest you start where the CodeIgniter constants end. Start with a comment to mark that the constants following are developer-defined. It will make a clear difference between your constants and framework constants.

database.php

If you are going to build a dynamic website, this is the basic necessity of your project. In this file, you need to set up all of your database credentials. Like Hostname, database username, database password, your database name, drivers, etc.

doctypes.php

It contains an array consists of many DOCTYPE as string values. There is not much to do with this until a very specific case arises.

foreign_chars.php

This file contains an array of foreign characters for transliteration conversion used by the Text helper. You need nothing to do with this.

hooks.php

In this file, you can define “hooks” to extend CodeIgniter without hacking (making changes in) the core files.

memcached.php

Here you can configure your Memcached servers for server-side caching.

migration.php

In this file, you can enable migrations whenever you want to do a schema migration and disable it back when you’re done. Migrations are disabled by default for security reasons.

mimes.php

This file contains an array of mime types.

profiler.php

This file lets you determine various sections of Profiler data.

routes.php

This file lets configure CodeIgniter routing by allowing you to rewrite/re-map URI requests to specific controller or controller functions.

smileys.php

This file contains an array of smileys for use with the emoticon helper.

user_agents.php

A very helpful file that contains four arrays of user data. This array helps to identify the browser, platform, robot, and mobile device data. The array keys are used to identify the device and the array values are used to set the actual name of that item.

**There is also index.html in almost all the folders which contain nothing but an error message printed: “Directory access is forbidden.”

#3 Controllers Folder in CodeIgniter Directory structure

All of your controllers, you will be creating and working on will reside in this folder. This directory will work as a core part for the developer. There is a file already present, named Welcome.php This is Welcome Controller acting as the default page of your application.

#4 Core folder of CodeIgniter

This directory will contain the base class of your application.

#5 Helpers directory in CodeIgniter

In this folder, you can create helper classes for your application.

#6 Hooks directory in CodeIgniter

If you want to make changes to the default and inner functionality of the framework. You can create custom hooks for that. By using hooks, you will not have to make changes in the core files. You will need to store those hooks files in this folder.

#7 Language folder

This folder will contain language files for the bilingual or multilingual applications.

#8 libraries folder

If you want to create custom libraries, you can create your libraries files here. Though, there are many useful libraries present in the CodeIgniter System directory to fulfill almost all the requirements.

#9 logs folder

This folder contains files related to the system logs.

#10 models directory of CodeIgniter

Like Controllers, this is one of the main directories for the developers. This folder will contain all the files that have code to interact with the database.

#11 third_party

This folder consists of all the third party plugins you will be using for your application.

#12 Views 

Like its name, this folder contains all the HTML pages those are viewable to the user end. Although we will be using PHP so, this will be PHP embedded HTML. That will be delivered after code execution to the end-user as simple HTML.

System directory in CodeIgniter Directory Structure

This is a folder where the CodeIgniter core resides. It contains core codes, helpers, libraries, and other files. These files are the base of this framework. It is not recommended at all to make any changes to these core files. If you are a beginner then you must not alter these files. If you will make changes to any of the core files. It will also cause an issue when you will update CodeIgniter.

Below is the list of organized consequence system folders –

#1 Core directory

You can say this part as the heart of CodeIgniter. All the core classes of the framework lie in this folder. Please do not modify the files of this directory. If you want any changes in the core functionality. Create hooks in the application folder to override the core behavior.

#2 Database directory

This directory contains database drivers, cache, query builder and other files needed for database operations.

#3 Fonts folder

As the name suggests, fonts folder contains font and related information and utilities.

#4 Helpers

This is the place where all the core helpers are located. These helpers are sufficient to fulfill almost all the requirements. The helpers included in this folder are array_helper, captcha_helper, cookie_helper, date_helper, directory_helper, download_helper, email_helper, etc.

#5 Language

The language folder contains the language files. It is useful in the case if your application is bilingual or multilingual.

#6 Libraries

Libraries folder consist of standard libraries. These libraries will help you with e-mail, calendars, file uploads, and many more. If you want to create your own libraries. Or you want to extend or replace the functionality of the standard ones. You can do it by creating files in the application/libraries folder.

user_guide in CodeIgniter Directory Structure

This folder is simply a reference guide for you. This is an offline version of the user_guide available on codeigniter.com. This is available for developers to learn the CodeIgniter basics. Whereas, you should not upload this directory when deploying your application on the server. As this is not a part of your application and will increase the server file size only

index.php

index.php is one of the most important files of this framework. This is the entry point of the framework. It always works as a frontend controller when the user sends any request. In this file, we can set the application environment and error level. We can define system and application folder name. Do not edit this file if you are a newbie to CodeIgniter.

Leave a Reply