Rapid Application Development with CodeIgniter
By Akash Mehta2008-02-17
In a framework-less PHP application, you'll typically have a number of seperate PHP scripts, each of which is accessed directly by the client. There might be a global header and footer, possibly with some standard functionality for database access. There are a number of problems with this approach, however, including inconsistent application entry points, repetition of code for standard tasks and so on. As the application grows, it can also become very inconsistent and hard to maintain.
The MVC design pattern goes a long way towards solving this. In MVC, your application is split into three parts - the Model, the View and the Controller. The Controller controls application flow and routing, handing off requests to other parts of the application. The Model manages data related to your application. Finally, the View represents the interface to your application, in this case our HTML front-ends. Views can contain basic logic, but most complex routines lie in the model.
The one problem with MVC, however, is that all this clean seperation is only effective if you observe it. You should start with the basic purpose of each section. For example, never access the database in your controller or view - that's what the model is for. Never output HTML in your controller or model, leave it to the view; and certainly never handle redirects within your view.
Still, here's what you should do. Your views can (and probably should) contain basic loops and simple if
logic. Views should be where output is constructed, with only the bare
essential data passed to them. Controllers can (and should) be full of
all the business logic your application needs, and models should
process data as needed without worrying about output. Keep this in mind
and you should get a lot out of using MVC for your application.
Tutorial pages:
|
|
|||||||||
You might also want to check these out:
|
Link to This Tutorial Page!

