How do you organize your template structure in CodeIgniter? How do you organize your template structure in CodeIgniter? codeigniter codeigniter

How do you organize your template structure in CodeIgniter?


A good file/folder structure would be the below:

website_folder/–––– application/–––––––– config/–––––––––––– autoload.php–––––––––––– config.php–––––––––––– ...–––––––– controllers/–––––––––––– examples.php–––––––––––– index.html–––––––––––– welcome.php–––––––– ...–––––––– views/––––––––---- templates/––––––––-------- backend.php––––––––-------- frontend.php–––––––––––– ....–––––––––––– example.php–––––––––––– index.html–––––––––––– welcome_message.php    –––– assets/–––––––– css/–––––––– js/–––––––– images/–––––––– templates/––––––––---- frontend/––––––––-------- css/––––––––-------- js/––––––––-------- images/––––––––---- backend/   ––––––––-------- css/––––––––-------- js/––––––––-------- images/–––––––– uploads/–––––––– index.html–––– system/–––– user_guide/–––– index.php–––– license.txt 

This is just a suggestion. So you will have your template views at views/templates and your css/js files at assets/templates/


I am totally agreed with web-johnny file folder structure but in my opinion he missed one thing define all your assets path in ./application/config/constants.php file e.g.

define('IMAGES_PATH', your_absolute_path_of_images_folder);define('CSS_PATH', your_absolute_path_of_css_folder);define('SCRIPTS_PATH', your_absolute_path_of_scripts_folder);

and so on... use these constants throughout the application so in this way if you ever need to change your file folder structure you just need to change the values of these constants.


Check the Modular Extensions HMVC, it's really useful when your project starts to grow. Modular Extensions - HMVC makes the CodeIgniter PHP framework modular. Modules are groups of independent components (typically, controller, model and view) arranged in one application sub-directory that can be dropped into other CodeIgniter applications.