In February we reviewed some baby steps to PHP in the context of a very simple project, finishing with the concept of a PHP function.
In March, when we took a side trip to the Google API, we also considered future presentations and discussions focusing on different PHP frameworks and content management systems (CMS) which can be extended to develop multiple complex projects.
Great idea. Especially since I won't have to present.
So all the big kids are playing with PHP frameworks. Especially Object-Oriented MVC frameworks.
But they seem so complicated. They can require a major time investment just to get started. It's like starting a serious relationship.
And all the smart people I know who are excited about their latest PHP framework relationship will also admit they've been burned more than once.
As Samuel Johnson said, a second marriage is the triumph of hope over experience.
So before we dive into the dating pool, let's take a few more baby steps.
A Wiki about Classes in general.
In PHP, a Class looks a lot like a list of variables and functions.
But an instance of a PHP Class is something else entirely. It's an Object. The variables become properties of the object. And the functions become object methods. Now we're in object-oriented PHP.
A Wiki about Objects in general.
Objects can be thought of as encapsulating their data within a set of functions designed to ensure that the data are used appropriately, and to assist in that use. The object's methods typically include checks and safeguards specific to the data types the object contains. An object can also offer simple-to-use, standardized methods for performing particular operations on its data, while concealing the specifics of how those tasks are accomplished.
A Wiki about software frameworks in general.
A software framework is an abstraction providing generic functionality which can be selectively changed by additional user written code, thus providing application-specific software.
Frameworks contain key distinguishing features that separate them from normal libraries:
- inversion of control - In a framework, unlike in libraries or normal user applications, the overall program's flow of control is not dictated by the caller, but by the framework.
- default behavior - A framework has a default behavior. This default behavior must actually be some useful behavior and not a series of no-ops.
- extensibility - A framework can be extended by the user usually by selective overriding or specialized by user code to provide specific functionality.
- non-modifiable framework code - The framework code, in general, is not allowed to be modified, excepting extensibility. Users can extend the framework, but not modify its code.
A Very Simple PHP MVC Framework
There are a number of large and comprehensive MVC frameworks for PHP, but a quick search will also turn up a number of smaller, simpler PHP MVC frameworks for small projects or learning.
And a number of people feel the best way to learn about them is to build your own.
Here's one example with a video (below) and code you can download: minimal but fully functional.
The principal limitation of this one is that it includes a single model and controller, but other tutorials explain different ways to add more.
- A conversation about the distinction between frameworks and content management systems, particularly with reference to Wordpress and Drupal. I contend Wordpress is an MVC framework, but it's a gray area.
- There was more discussion than I expected about what belongs where. In particular how much logic should there be in a view or controller.
- The consensus seemed to be in favor of fat models, thin controllers and very thin views.
- As much logic as possible should be pushed down to the model(s). Controllers should basically manage navigation.