If you download and unzip CodeIgniter, you get the following file structure/folder structure:
Application
- cache
- Config
- Controllers
- core
- errors
- helpers
- hooks
- language
- libraries
- logs
- models
- third-party
- views
system
- core
- database
- fonts
- helpers
- language
- libraries
In a CodeIgniter application, the folder structure plays a crucial role in organizing files and directories. Here’s a breakdown of the typical folder structure in a CodeIgniter application:
- application: This directory contains all the application-specific files including controllers, models, views, helpers, libraries, and any other custom code.
- config: Configuration files such as database configuration, routes, constants, etc.
- controllers: Contains PHP files that handle application logic, each representing a controller.
- core: Custom core classes can be placed here, though it’s not commonly used.
- helpers: PHP files containing functions that assist in tasks throughout the application.
- hooks: Contains hook files that allow you to tap into the execution process of the CodeIgniter core.
- language: Language files for internationalization.
- libraries: Custom libraries or third-party libraries used in the application.
- models: Contains PHP files that handle database interactions.
- third_party: Third-party libraries that are not natively supported by Composer.
- views: Contains HTML files mixed with PHP code that represent the user interface.
- system: This directory contains the core files of the CodeIgniter framework. It’s advisable not to modify these files unless necessary, as it may lead to compatibility issues during updates.
- public: Also known as the webroot or document root directory, this is where your publicly accessible files are stored. This directory should be set as the document root for your web server.
- index.php: The entry point for all requests. All requests to your application go through this file.
- assets: Contains static assets like CSS, JavaScript, images, etc.
- .htaccess: Used for URL rewriting and other server configurations if you’re using Apache.
- tests: Contains test files for your application. This directory may not be present in all CodeIgniter applications, but it’s recommended for maintaining test suites.
- vendor: If you’re using Composer to manage dependencies, this directory contains all the third-party libraries installed via Composer.
- writable: This directory typically contains files that need to be writable by the web server. For example, logs, cache files, and session files may be stored here.
This folder structure provides a logical separation of concerns and makes it easier to manage different aspects of the application. It follows the MVC (Model-View-Controller) pattern, keeping models, views, and controllers separate for better organization and maintainability.