Can anyone provide a very simple example of Hello World in MVC approach to PHP?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
The QuickStart of Zend Framework is a not too bad example of "simple application" (not an "Hello World", but not much more -- and using MVC for an "Hello World" application is a bit like using a nuclear bomb to kill a bug), based on Zend Framework, and using MVC.
After, if you want to get a bit farther, you can take a look at the electronic book Survive The Deep End! -- still work in progress, but an interesting read anyway.
That's with ZF ; I suppose you can find the same kind of stuff with other MVC Frameworks like Symfony or CakePHP.
Here's the most basic example. Your index.php file is the controller, gets some data from the model, then includes the HTML via a view file.
.
Here's some "Hello, World" MVC:
Model
View
Controller
The main idea is to keep separate the data access (model) from data presentation (view). The controller should be doing no more than wiring the two together.