php mvc tutorial for beginners-Model-View-Controller

In most PHP web applications, you won’t have a strict MVC
setup. In fact, it’s quite a lot of work to go full-on MVC with
PHP.

Getting a web project off the ground can be cumbersome and technically demanding, especially when
 using older methods of development. Cake, however, makes the initial steps of building a
web application easy. Rather than run installation scripts from the command line,
Cake comes prepackaged as a folder you simply drop onto a server and is ready to run.
The command line does come in handy once you begin building onto the framework.


With Cake, creating user flows in the application early on is simple and can improve
communication with clients. In some cases, a run-through of the application can be developed
in minutes, allowing the client to get an idea of the project’s architecture.
Once a project is fleshed out and launched, site maintenance is also improved thanks
to Cake. Because of its hierarchy and organization, as well as its effectiveness at limiting
redundancy, Cake helps developers adjust a web application on the fly. Cake also supports
test databases and URL routes for testing new features or versions of web applications on
the live setup.

Model-View-Controller
Cake enforces an MVC structure for your web applications. Basically, it effectively separates
typical operations into specific areas: models for all your database interaction, views for all
your output and displays,and controllers for all your commands/scripts for input and program flow.

The client sends a page request to the application, either by typing a URL or by clicking
alink of some kind. Byconvention, a typical URL is usually structured like this:

http://Domain-name.com/Application/Controller/Action/Parameter 1,2,3........

The benefit of using MVCto develop web sites is that repeated functions or tasks can be
separated, thus allowing for quicker edits. It can even help in debugging. Say an error keeps
occurring during the interaction with the database. Usually the problem will be somewhere
in a model. Knowing that all database interactions occur in just one place makes it easier to
solve problems.

How about a tips over the mvc (model view controller) architecture pattern.

MVCstructures are useful because they allow you to separate the different processes of
the web site. When needing to change or add new form fields, for instance, you need only to
locate the appropriate view file and make the change. Instead of sifting through PHP output
functions or scripts,you know that all the views are contained in the viewsfolder.The same is
true of controllers and models. Certain functions are available across the whole application
without requiring any includes. Managing all the paths for include files or libraries in a non MVC
application can become difficult as the program grows.


Model ---->Handles all database functions.                         app/models/Model-name.php
View-------> Handles the presentation layer and displays.    app/views/View-name.ctp
Controller---> Handles all logic and requests.                     app/controllers/Controllername_controller.php


MVC is not about removing all logic from the view; it is about removing
domain (or business) logic from the view. Differentiating display and business logic is not
always easy.

For many developers, the goal is not simply to have separation of the display and
application but to extract as much logic as possible from the display.The commonly
expressed desire is to “keep designers out of my PHP”; the implication is that designers
either can’t learn PHP or can’t be trusted with PHP. Smarty cannot solve this problem.
Any template language that provides the ability to implement complex logic gives you
more than enough rope to hang yourself if you aren’t carefu