Main Content

Real life PHP application using our course training MVC example

Archive - Originally posted on "The Horse's Mouth" - 2016-06-05 07:26:58 - Graham Ellis

Yesterday, I had a requirement to write a multistage web application, using an existing look and feel template, and I did so using the training example from our Learning to Program in PHP. Quick and easy - most of the work is (or was) in working out the text and factors involved - the data - rather than adopting the standard template. And then there was a job of work to write the support page describing to people why I'm providing this application ...

Wiltshire Council has concluded that the current level of subsidy given to bus services in the county cannot be sustained, and is to be reduced after the next council elections. There are a number of options that may be open to achieve this goal, and the choice made will affect other things too like how much expenditure is required to compensate from other budgets, whether the savings will be sustained in future years, and whether we'll be left with a system that's usable on these routes. The application puts visitors to the Option 24/7 web site into the position of the decision makers, asking the application user to apply importance factors to each of ten things that should be considered in the outcome, then it ranks the eight options I have been able to identify in terms of which will achieve the weighted aims best.

Here's the choice page you're offered:

And you can run the application [here]. You can also read the support page [here].

Although we're hosting the page on a site that's headlining the promotion of the options available under the new Bus Services Bill that's going through Parliament, the intent is to offer a level evaluation of all the options. As the new bus powers are intended to assist larger public transport authority areas - Mayoral ones, and larger unitaries (such as Wiltshire, which is the third largest unitary) - it's no great surprise that many of the weighted results come out in favour of the new systems; some don't though, and old systems will still be available. It's also very instructional to learn about just how much (or little) the scores vary - where the decision will be a close choice between options, and where it's going to be darned obvious that something should be eliminated early on.

At this stage, we're asking that the council applies for the powers to implement the newly avaialble options by declaring itself a competent authority with public support to look at the options (and apply them if it turns out they're best for us) and a sensible economic area for it to work - or at least be worth looking at. This is an application to the Secretary of State for Transport. We're also asking that the council seriously investigates all the options not just the ones they had in their consultation which was prior to Bus Service Bill publication. It would be very unfortunate, to say the least, if a lack of preparation and investigation work meant that when the time came for a decision to be made the new options couldn't even be on the table, and the least draconian option in the mix involved the end of all support for evening buses, Sunday buses, and many other reductions on town, intertown and rural services that might have been avoided.

When I get involved in something like this, I do so through openness as strength of knowledge (learning a lot as I go, and listening to the experts who help me). I also look pragmatically at the data and don't try to "gloss" it. I would rather have the system come up with the right solution, rather that the one I advocate, if they turn out to be different. I'll admit to getting really hacked off by people who try to be selective with their data, who don't publish complete information, and who attempt to fillibuster or kick options they're not sponsoring into the long grass past decision date. But that's an aside, and doesn't stop me being open.

I promised the technical data behind the application. It's an easy enough PHP application based on our MVC traning framework and the source of all the files are available via [here] for you to see the whole thing - and even duplicate it on your own server if you wish. You are also very welcome to ask me questions, and I would be happy to sit down with people and play about with factors which are my best estimates to see what difference changes make there.

Files ..
• Application Framework [here] [CONTROLLER] and [FRAMEWORK]
• Business Logic (actual calculations) [here] [MODEL]
• Template for presenting the results [here] [VIEW]
• Data file describing each option [here]
• Data file describing each effect to be weighed up [here]
• Data file of weights [here]
• Web Helpers - utility routines under the framework [here] [HELPERS]
There is no [ROUTER] in this application - a simple single URL points to the framework.
Data is passed in to the single URL using the POST method, with sessions maintaining state.
(Note use of tabs as separators in the data files - take care if you cut and paste not to replace by spaces!)