Codeigniter 4 Create Controller, Model, View Example

Codeigniter

Nicesnippets

9173

07-08-2020


Hi Guys,

In this example,I will learn you how to create controller, model and view in codeigniter 4.you can easy create controller, model and view in codeigniter 4.

In this tutorial, you have learned how and where to create controller, models, and views in CodeIgniter 4 framework.

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:

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:

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>

It will help you.....


Recommended Posts