What is MVC?
From Wikipedia-
Model–View–Controller (MVC) is an architectural pattern used in software engineering. Successful use of the pattern isolates business logic from user interface considerations, resulting in an application where it is easier to modify either the visual appearance of the application or the underlying business rules without affecting the other.
In MVC, the model represents the information (the data) of the application; the view corresponds to elements of the user interface such as text, check box items, and so forth; and the controller manages the communication of data and the business rules used to manipulate the data to and from the model.
In simpler words-
1. Model handles all our database logic. Using the model we connect to our database and provide an abstraction layer.
2. Controller represents all our business logic i.e. all our ifs and else.
3. View represents our presentation logic i.e our HTML/XML/JSON cod
MVC Structure Work Flow
Existing PHP Framework
PHP Popular Frameworks
- Zend
- Symfony
- CodeIgniter
- CakePH
PHP Application Frameworks
- Joomla
- Durpal
- Wordpress
- OSCommerce
- Magento
To write the own framework, first need to understand the structure of any one the above frameworks ( zend, symfony, codeigniter or cakePHP).
Mission
Our mission is to build a PHP framework with MVC that is
- Simple
- Reusable
- Fast
- Extensible in future
- light-weight
Core Components
For the MVC framework structure we need the following components
1. Controller
2. Model
3. View & Layout
4. Access Control
Directory Structure
The framework should follow the standard directory structure to organize or hold the files.
- /Framework or root folder
- /application
- /controller
- /model
- /view
- /layout
- /lib
- /config
- /public_html
- /css
- /images
- /scripts
The purpose of the each directory
application - application specific code
config - database/server configuration
lib – library of framework code
public_html - application specific js/css/images/scripts
Coding Conventions
- mySQL tables will always be lowercase and plural e.g. items, cars
- Models will always be singular and first letter capital e.g. Item, Car
- Controllers will alway be singular and first letter capital e.g. Item, Car
- Views will have plural name followed by action name as the file. e.g. items/view.php, cars/buy.php
