Showing posts with label php mvc. Show all posts
Showing posts with label php mvc. Show all posts

Wednesday, 5 December 2018

Hello World in MVC


MODEL: It is a class file which contains the Database connectivity queries inside it.
CONTROLLER: This file access the methods and variables declared.
VIEW: It contains all the HTML and view page.
In Controller create a file named "hello.php". This file will be saved in the Controller folder.

controller/hello.php

<?php
class Hello extends Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->view->render('hello/index');
}

Create a file index.php and place inside views folder.

views/hello/index.php

<!DOCTYPE html> 
<html> 
<head> 
<title>Hello World</title> 
</head> 
<body> 
<p>Hello World!!</p> 
</body>
</html>

Now run the file in any browser: http://localhost/mvc/hello/index