Close

🔰 PHP Programming Tutorial 5 - Controllers in CodeIgniter 4 🔰


What is Controller?

A Controller receives the user input and validates it, and then passes the input to the Model. It performs interaction on the model objects.

It is a simple class file. The name of the class is associated with URI.

The first letter of a class name must be capital.

CodeIgniter 3 Example

<?php  class Home extends CI_Controller { 	 	public function index() { 		echo "Welcome to CodeIgniter 3"; 	}  } ?>

Run in URL:

http://localhost/proejct/index.php/home/

CodeIgniter 4 Example

<?php namespace App\Controllers;		  class Home extends BaseController { 	 	public function index() { 		echo "Welcome to CodeIgniter 4"; 	}  } ?>

Run following command in cmd/terminal from project’s root directory:

> php spark serve     http://localhost:8080

Run in URL

http://localhost:8080/index.php/Home/index

In above example,

Home.php is a default controller. You can alter the default namespace, controller and method from /app/Config/Routes.php.



😉Subscribe and like for more videos:
https://www.youtube.com/@chiragstutorial
💛Don't forget to, 💘Follow, 💝Like, 💖Share 💙&, Comment

0 Comments
Leave a message

 

Search Current Affairs by date
Other Category List

Cookies Consent

We use cookies to enhance your browsing experience and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Cookies Policy