Develop Website Using MVC Model Views Controllers Part 1

In this post I’m discussing A practical way to Develop Website using MVC Model Views Controllers In last post I’ve discussed MVC at basics Today in this post I’ll discuss MVC at a basic practical methodology.

Introduction:
Here in this Practical PHP project based MVC development I’m explaining complete customized MVC , and I’ve never used any PHP frameworks here this post best for beginners to MVC development.

Requirements:
PHP, apache server to run PHP.

  • if you don’t have knowledge of PHP language or if you don’t have PHP installed in your system just follow this link to learn and get ready.
  • You should have good knowledge in HTML-CSS but here I’m only talk about PHP server side codes only.
  • You should have good Notepad editor. I prefer Sublime-Text Download from here. it has different versions for Linux, windows, Mac OS users as well.
  • You should have good browser. i prefer Mozilla FireFox with FireBug extension. 

Getting start..
Here we go..

Directory Structure:
First of all You must create a directory structure to get all the things easy and MVC requires to form a Directory structure because of Data-abstraction . here we hide the actual page and we get control over URL bar using Routes.

Go to web root directory.
-In case of windows XAMPP htdocs folder
-In case of Linux go to /var/www/html/ folder

Create directory structure as the following:
Create Folder names as here given. Create App and Public folder which is main 2 folders.
App Folder Contains 4 main folders Controller, Core, Model, View and View Folder Contains
home folder inside it. Public folder is entry path of the user to your web development.

Create Following files in given folders:
Brief Explanation:

The App folder contains all the back-end operational files.

Controller: Controller is used to govern the user who uses the website, the Controller folder contains Home.php file which is user controller. we can create further more controllers here by creating files. Here the Home.php is a sub controller to our Base controller. we’ve used Home controller to work on Home page monitoring.

Core: The Core folder is very important folder and it’s heart of the MVC the Core folder contains all the necessary files. to run a MVC it has main 2 that is App.php and Controller.php and additional db.php is for connecting Database to our MVC. App.php contains all the necessary codes about

  • Creating Routes and URL management.
  • Managing Controllers Base as well as Sub Controllers.
  • Connecting to the Models getting data from the Models.

Controller.php: This is our Base Controller. the functions of our Base controller is it referenced by the sub controllers (Home.php) which we’ve created in our Controller folder .

Db.php is our Database Configuration file. it contains database login credentials.

Models: Models are the resources of the current stage of MVC means it takes all the informations such as current users session and it responds to controllers and provides related data on the Session. Model folder contains User.php which takes the current user information.

Views:Views are End user views where all the HTML CSS files UI system of website contains. It does’t contains any server side codes. just for viewing purpose these are used. here we have Home folder in it and you can put any files into that.

PUBLIC: its a entry path of our website so it should has index.php

I hope this article was helped you to understand basic file structure and basics of MVC. In next article I discuss about Routes and managing Web-server using .htaccess file.and don’t miss whole series Develop Website using MVC Model Views Controllers 

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *