Basic knowledge of MVC architecture in PHP ____php

Source: Internet
Author: User
Tags html tags microsoft sql server php class
MVC, which stands for Model-view-controller, are a really good way to develop clean, scalable, powerful and fast Applicati ONS in the least amount of the time and with the least effort. Before exploring MVC, this is article begins with a brief introduction to PHP.

PHP is a open source programming language that was developed to 1994 by Rasmus Lerdorf. PHP originally stood for personal home pages but now stands for hypertext preprocessor, which is a recursiv e acronym. It is a loosely typed server-side scripting language used to build WEB applications. A scripting language is a language this does not need to be compiled the use. and ' loosely typed ' languages are those in which there-no need to define the type of a variable.
today, more than million domains use PHP, including Facebook and Yahoo.
PHP is easily embedded with HTML, and are used to manage dynamic content and the databases of websites or, we can say, Web applications. We can use PHP with many popular databases like MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server.

How to PHP works on servers
When a client (browser) sends a request for a PHP page to the server, the server reads the requested file from the disk (s Torage) and sends this file to the interpreter. The interpreter then runs the PHP code, fetches the DB data (if required) and puts it into HTML tags. Once The interpreter completes its tasks, it sends "result" to "server", which sends this data to the client (bro Wser) that made a request for this page.

MVC Architecture with PHP
The Model-view-controller concept involved in software development evolved in the late 1980s. It's a software architecture built on the "idea" that the logic of the application should is separated from the. A system developed on the MVC architecture should allow a front-end developer and a back-end developer to work on the SAM e system without interfering with each of the other.

The concept of model-view-controller related to software development developed in the late the 1980s. It is a software architecture based on the idea that the application logic should be separated from its presentation. Systems developed on the MVC architecture should allow front-end developers and backend developers to work on the same system without interfering with each other.

Model
Model is the name given to the component that would communicate with the database to manipulate the data. It acts as a bridge between the View component and the Controller component in the overall architecture. It doesn ' t matter to the Model component what happens to the the ' the ' the ' the ' it is passed to the View or Controller components.

Model is the name that communicates with the component and is used to process data. It acts as a bridge between the view component and the controller component in the entire architecture. It has nothing to do with the model component, and when it is passed to the view or controller component, the data changes.
The code snippet for running first_model.php is:

<?php class Model {public $string; the public Function __construct () {$this->string = "Let's start PHP with MVC";} ?>

View
The View requests for data from the Model component and then it final output is determined. View interacts with the user, and then transfers the user's reaction to the Controller component to respond. An example of that is a link generated by the View component, when a user clicks and a action gets triggered in the CONTR Oller.

The view requests data from the model component and then determines its final output. The view interacts with the user and then passes the user's response to the Controller component to respond accordingly. An example of this is the link generated by the view component when the user clicks and triggers an action in the controller.
To run first_view.php, type:

<?php class View {private $model; private $controller; public function __construct ($controller, $model) {$this->co Ntroller = $controller; $this->model = $model; The Public function output () {return ' <p> '. $this->model->string. "</p >"; }}?>

Controller
The Controller ' s job is to handle data, the user inputs or submits through the forms, and then Model updates this Acco rdingly in the database. The Controller is nothing without the user ' s interactions, which happen through the View component.

The controller's job is to process the data that the user enters or submits through the form, and then the model is updated accordingly in the database. The controller does not have user interaction and occurs through the view component.
The code snippet for Runnin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.