PHP, Zend Framework and Other Crazy Stuff
Archive for April, 2007
Complex Web Pages with the Zend Framework?
Apr 19th
27 March 2008:
With the inclusion of Zend_View Enhanced as first documented, discussed and publicised in this blog series, in the Zend Framework as of 1.5.0 I’d like to thank everyone involved in the process. A few of you pioneered it’s implementation and provided immense feedback which tailored the proposal to some specific needs, others kept bringing it up on the mailing lists and to the attention of the Zend reviewers, and others still spent a lot of time converging ideas towards a unified proposal. It just goes to show that the community really does have the power to influence the big picture and get stuff done!
The rest of this series can be accessed as follows:
http://blog.astrumfutura.com/archives/283-Complex-Views-with-the-Zend-Framework-Part-3-Composite-View-Pattern.html
http://blog.astrumfutura.com/archives/285-Complex-Views-with-the-Zend-Framework-Part-4-The-View-Factory.html
http://blog.astrumfutura.com/archives/288-Complex-Views-with-the-Zend-Framework-Part-5-The-Two-Step-View-Pattern.html
http://blog.astrumfutura.com/archives/291-Complex-Views-with-the-Zend-Framework-Part-6-Setting-The-Terminology.html
Recently I’ve been involved in a long discussion about the Zend Framework on the PHP Developers’ Network forum. Our approach was to pick a simple application (we decided to borrow the Java BluePrints Pet Shop for J2EE) and starting from a basic “Hello World!” example for the Zend Framework work towards a fully functional example. Of course, one of our goals wasn’t just to “do it”, we wanted to explore the framework in greater detail, and identify how best to use, misuse, subclass, and where it was logical to even replace components should they prove deficient for our needs.
After wrangling about configuration, the advantage/disadvantage of build tools (I love Phing and cannot survive without it!), the location of the bootstrap file, and a few other odds and ends we finally put up the “Hello World!” example in subversion. Many thanks to Chris Corbyn of Swiftmailer fame for contributing the repository!
http://w3style.co.uk/devnet-projects/pet-store/trunk/
We then decided to look at how the Zend Framework implements Views. In essence, the framework isn’t as developed in that respect as its peers. A simple page is easily built using a Zend_View instance, a PHP/HTML template for a list of entries, and a few view helpers and filters. After that however, a complex page becomes progressively more difficult. This is complicated in part by the growing practice of instantiating Views using a helper function on the Controller – unfortunately this is unusable since it introduces coupling making re-use more difficult in other applications where the View has been subclassed.
Back on track, the main problem of a complex View, is that the current Controller is only aware of a subset of its own required Model (data) and the current View. So how do do you get the View to include extra sections – for example, details from Technorati for your blog – which are common to ALL pages?
The Zend Framework currently suggests using a Controller’s _forward() method – basically if your current View needs data from Technorati, then forward from the current Controller to a “TechnoratiController” to fetch it and assign it to the View, and then _forward() back. This works for simple things – but what if there are three, or even more sections? What if some sections, have additional embedded sections? How in heaven’s name are you supposed to track all those _forward()’s?
While pondering the problem, we all agreed using the Controller _forward() was not a good idea – it’s prohibitively complex, forces Controllers to become aware of other (possibly unrelated) controllers, and in general doesn’t promote reuse. I haven’t measured the performance impact of such a tactic but it can’t be good. We also determined the Zend Framework’s view helpers were of limited use being simple classes designed to offer a single public method to templates.
Finally we decided to visit two design patterns to help name the problem and offer a possible solution: Composite View and View Helper. So far we’ve just implemented a very basic Composite View (KISS) to further the brainstorming. But it shows a lot of promise in offering a simple, effective solution to building complex web pages with the Zend Framework – granted it breaks the normal practice, and takes subclassing to introduce, but it’s a reusable solution.
I’ll visit Composite View in more depth soon – for the moment here’s the J2EE BluePrints page for the design pattern: Composite View. If anyone knows of a really good example in PHP or Ruby, it would be great to hear about it!
On the View Helper bit – the Zend Framework seems to persist a belief that only Controllers should interface with the Model layer (i.e. Database and associated Model classes). This Model-Push strategy can be complemented with an equally valid Model-Pull strategy – where View Helper classes have the ability to directly access and read data from the Model to pass to the requesting View. This completely avoids the fickle tactic of Controller forwarding and the complexity it tends to introduce into an application.
Stay tuned for a deeper look at both these patterns – specifically how they can be brought to bear on the Zend Framework with a little subclassing of Zend_View.
S.T.A.L.K.E.R.: Shadow of Chernobyl
Apr 5th
I finally got my copy of the game at the weekend, played a little, got the patch, found my save games were incompatible, restarted, and replayed (sigh) a little more. It’s an interesting game, full of interesting ideas and sometimes exasperating combat. Surprisingngly, given the level of buginess so evident (and definitely not addressed by that patch) it’s a good game overall. So it gets a thumbs up from me, with a sidenote that you should have a pretty decent rig to really get the most out of the game, and should have a certain tolerance for the inevitable bug or two.
Even so, there are some spectacular misses. Gameplay stands by itself very well, so these aren’t as important as they would be to a lesser First-Person Shooter, but still… The most obvious is that the settings menu for Video Options is a mess – Antialiasing and Anistrophy are non-existent. One is simply not working, the other is useless because STALKER’s game engine uses a weird rendering system that doesn’t support it. I’ve been reading the TweakGuide.com examination released earlier and all is not lost – there are tweaks you can make since the game is capable of being modded by extracting the content archives (much like Oblivion and Medieval 2). TweakGuide also comments on the effectiveness of some low-level options (which don’t seem to work better than the “medium” ones). Also HDR, important for GeForce 6 series GPU’s, is not a separate setting to be disabled.
Back to the game play – STALKER excels at a few graphical additions (even with the above). The most obvious is the weather. When it rains, it pours. When it let’s loose lightening, your video card takes notice. The second is the day/night cycle – and night is something to really take care with. Unlike Oblivion, or other half-assed attempts at day/night cycles, STALKER just takes the realistic of approach of making the sun set and rise at genuine times. Simple, effective. Half Life 2: Episode One (the level with the underground garage populated by Zombies) is a close match for how you’ll feel when night arrives. Even bumping up the gamma level doesn’t help with visibility. Even the flash light isn’t much help beyond a certain range. This really packs a cool punch – especially when you have to spend the next 7 hours of gametime (a lot less in real time of course
) stumbling around in the dark hearing the howls of a pack of mutant dogs and barely being able to see them when get close. Sychronising attacks with lightening strikes becomes a quickly learned skill
.
The other cool thing is the “ALife”, watching mother nature at war with packs of Blind Dog mutants run into confrontations with those mutant boars around this corner, or something even weirder around another – all at random in a natural fashion. It’s cool to watch – especially once you realise those creatures have defining habits. At the start, I remember finding the body of a fellow Stalker surrounded by mutant dogs. After shooting up two, and scattering the rest I returned some hours later to find the escapees of my first attack had returned to the body and were apparently ravaging it – and their dead compatriots. I almost felt sorry for the poor sod whose pixelated body was being gnawed on, I was even tempted to use the “drag body” action to move him to a place safe from the local man-eating wildlife.
A few places where it goes wrong includes the mission system. Missions are obviously not finished in full – most are given by a handful of Traders, or Stalker leaders. Most come with no other in-game scenery, events, or NPC interaction other than the text descriptions. Oblivion was far better – of course Oblivion has voice overs for ALL the text which made it more immersive to start with. This lack of gloss in some areas, and the opposite in others is a sad thing – finished this game would have hit a few 90%+ marks in reviews, rather than the telling 80%+ it seems to be getting.
Overall, it’s flawed and buggy, but that’s easily forgiven once you jump into unique action. My score? I’d go with an 85% and hope it prods future FPS’s to new levels of originality.
