In this CodeIgniter 4 controller, model, view tutorial, we would love to share with you how and where create model, view, controller and CodeIgniter 4.
You have known about Codeigniter is an MVC pattern based PHP framework. Where
Controllers act as glue code, marshaling data back and forth between the view (or the user that’s seeing it) and the data storage.
Models manage the data of the application and help to enforce any special business rules the application might need.
Views are simple files, with little to no logic, that displays the information to the user.
Create a Controller in CodeIgniter 4
All Controllers are typically saved in /app/Controllers. If you want to create a new controller in codeigniter 4. So go to app/controller and create a new php file and update the following code:
<?php namespace App\Controllers; use CodeIgniter\Controller; class Blog extends Controller { public function index() { echo 'Hello World!'; } }
Create a Model in CodeIgniter 4
All Models are typically saved in /app/Models. If you want to create a new model in CodeIgniter 4. So go to /app/Models and create a new PHP file and update the following code:
<?php namespace App\Models; use CodeIgniter\Model; class UserModel extends Model { }
CodeIgniter 4 Create a View
All views are typically saved in /app/Views. If you want to create a new views in CodeIgniter 4. So go to /app/Views and create a new PHP file and update the following code:
<html> <head> <title>My Blog</title> </head> <body> <h1>Welcome to my Blog!</h1> </body> </html>
Conclusion
In this tutorial, you have learned how and where to create controllers, models, and views in CodeIgniter 4 framework.