Application Structure or Folder Structure in Codeigniter 4
Folder Structure in CodeIgniter 4
CodeIgniter 4 has a specific folder structure that helps to organize your application files and folders. Here is an overview of the folder structure:
App Folder
- Purpose: Contains all application-specific files and folders
- Subfolders:
- Config: Configuration files
- Controllers: Controller classes
- Models: Model classes
- Views: View files
- Libraries: Custom libraries
- Helpers: Custom helpers
- Language: Language files
- ThirdParty: Third-party libraries
Config Folder
- Purpose: Contains configuration files for the application
- Files:
- App.php: Application configuration
- Database.php: Database configuration
- Email.php: Email configuration
- Validation.php: Validation configuration
Example: app/Config/App.php
<?php
namespace Config;
use CodeIgniter\Config\BaseConfig;
class App extends BaseConfig
{
public $baseURL = '(link unavailable)';
public $indexPage = 'index.php';
}
Controllers Folder
- Purpose: Contains controller classes
- Files:
- Example.php: Example controller class
Example: app/Controllers/Example.php
<?php
namespace App\Controllers;
use CodeIgniter\Controller;
class Example extends Controller
{
public function index()
{
// Handle the request
}
}
Models Folder
- Purpose: Contains model classes
- Files:
- Example.php: Example model class
Example: app/Models/Example.php
<?php
namespace App\Models;
use CodeIgniter\Model;
class Example extends Model
{
protected $table = 'examples';
}
Views Folder
- Purpose: Contains view files
- Files:
- example.php: Example view file
Example: app/Views/example.php
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>Example</h1>
</body>
</html>
Libraries Folder
- Purpose: Contains custom libraries
- Files:
- Example.php: Example library class
Example: app/Libraries/Example.php
<?php
namespace App\Libraries;
class Example
{
public function doSomething()
{
// Do something
}
}
Helpers Folder
- Purpose: Contains custom helpers
- Files:
- example_helper.php: Example helper file
Example: app/Helpers/example_helper.php
<?php
function example_helper()
{
// Do something
}
Language Folder
- Purpose: Contains language files
- Files:
- en.php: English language file
Example: app/Language/en.php
<?php
return [
'example' => 'Example',
];
ThirdParty Folder
- Purpose: Contains third-party libraries
- Files:
- example.php: Example third-party library file
Example: app/ThirdParty/example.php
<?php
namespace ThirdParty\Example;
class Example
{
public function doSomething()
{
// Do something
}
}
I hope this helps! Let me know if you have any further questions or need more information.