turbonerd
turbonerd

Reputation: 1306

The MVC approach to OO-PHP and WordPress plugins

I'm starting to look at Object Oriented PHP. To date I've developed a large number of PHP systems with a procedural approach, but I think it's time to move forward.

One of the projects I'm working on at the moment is a Grade and Handicap Calculation plugin for WordPress. In short, the plugin takes table tennis players' results from uploaded CSV files and works out their grading for handicap tournaments.

I'm using WordPress because my table tennis club's website uses WP and if it works for them I can potentially give it to other clubs/leagues and they too will be able to install the plugin and have access to a fully-fledged grade and handicap system.

Outside of WordPress, I'm reasonably confident that I could develop such a system in OO-PHP using the MVC pattern. It would probably look something like this:

Controller

  1. Create an instance of the Model
  2. Deal with "navigation", i.e. GET/POST requests, and work out which page templates to display accordingly

Model

  1. Deal with uploading and storage of files
  2. Update and select information from database
  3. Host mechanism for working out players' grades

View

  1. Admin pages, i.e. settings and uploading files
  2. Grades page, displaying players' grades and handicaps
  3. Results page, where specific users can see individual players' results (mostly for debugging purposes)

Please correct me if I'm wrong, as I've only learnt this pattern in the past 30 minutes or so, but by my logic that is a true MVC approach to creating this system.

However, once I bring WordPress plugins into the equation, I'm starting to struggle with the following questions:

All of these questions probably have the same answer, and I know it's just semantics, but I'm keen to try and get this right early on so I can truly get my head round the MVC pattern of Object Oriented PHP.

Thanks in advance,

Upvotes: 3

Views: 1242

Answers (2)

tamilps2
tamilps2

Reputation: 46

If you are looking for a better place for learning MVC, this would be it.

Upvotes: 1

apoq
apoq

Reputation: 1454

Hope I'm getting this right.

  1. Can't tell you about CSS, as I just keep those defined in my layout files (view).

  2. Heavy logic can be put into services (external Class), and then being ran in controller. You'll keep your controller 'thin'

  3. Similar to previous one. You can have your menu stored as a model (which doesn't have to be strictly DB related, but also XML/JSON/array data), and then call your add/remove actions in controller.

Upvotes: 0

Related Questions