Blog
Zend_Form_Decorator_ViewScript
by Daniel on Dec.08, 2009, under Blog
Ok, not exactly breaking news, but I’ve just discovered the Zend_Form_Decorator_ViewScript class, the Zend DevZone article covering it, well, it helped me find it, but the examples are pretty useless if you want it to actually work! (No surprises there then, sorry DevZone.)
So to that end I thought I’d blog.
Zend Form Decorators can be hard enough to twist your brain around at the best of times. But the ViewScript Decorator makes forms easy again. You can apply the ViewScript decorator to any Zend_Form element, though I’d have thought that using it on the Form itself is all you’d really need.
File: ./application/forms/Example.php
<?php
/**
* ViewScript Decorator example form
*/
class Form_Example extends Zend_Form
{
/**
* Initialise
*
* Set up the form, that's down to you,
* set the ViewScript decorator for the form
* @access public
*/
public function init()
{
/* ... Initialise my form ... */
$this->setDecorators( array(
array( 'ViewScript', array( 'viewScript' => 'forms/example.phtml' ) )
) );
}
}
?>
Remember that the path forms/example.phtml is relative to the configured view script directories. So in my app these are ./application/views/scripts/:./application/modules/default/views/scripts/:./application/modules/admin/views/scripts/.
Inside the view script, the form element you’re decorating is assigned to the element view property. So inside the view script ( $this->element instanceof Zend_Form ) === true.
That just leaves you with the view script itself now. Well, they’re just like any other view script except you only have $this->element property, your view helpers remain available to you as always.
File: ./application/views/scripts/forms/example.phtml
<form id="exampleForm" action="<?php echo $this->element->getAction() ?>" method="<?php echo $this->element->getMethod() ?>">
<h2>Your Details</h2>
<?php echo $this->element->email ?>
<?php echo $this->element->dob ?>
<h2>Account Details</h2>
<?php echo $this->element->username ?>
<?php echo $this->element->password ?>
<?php echo $this->element->passwordconfirm ?>
<h2>Terms & Conditions</h2>
<p>Read our <a href="<?php echo $this->url( array(), 'terms_and_conditions' ) ?>">Terms & Conditions</a> before signing up.</p>
<?php echo $this->element->termsandconditions ?>
<?php echo $this->element->submit ?>
<p class="small">NOTE: This is where you may want reassure your visitors that you're to be trusted.</p>
</form>
Now that’s a pretty simple example of how you’d use the ViewScript decorator. You may be able to achieve that markup using only the other decorators. I don’t know, and I can’t really be arsed enough to find out. I plan to just keep it simple and have a view script for each form that needs it, and use other decorators for the individual form elements.
It is now down to you to build the <form/> element, the individual form elements are still automatically generated though so you still get all those fancy features that made you want Zend_Form in the first place. Simply echo them out.
No carbon offset for me
by Daniel on Mar.21, 2009, under Blog
So, how do you run out of carbon offsets? For that matter, what kind of carbon offset will 50p buy me anyway? I mean, it can’t really cost a mere ( 50p x $number_of_rockers ) to “offset” ALL the evil anti-green-enviro-stuff entailed in putting on the festival, if it costs ( £10 x $number_of_rockers ) just for Ticketmaster to sell the damn tickets over t’intertubes.
Now, Download is put on by LiveNation, and I had a suspicion that Ticketmaster were owned by LiveNation. A quick google has told me that they weren’t bought but “merged”. So yeah, my “outrage at the evil faceless corporation queezing the blood from the innocent” nerve is running on overdrive at the moment.
Reflection
by Daniel on Mar.18, 2009, under Blog
Just spotted this on Google Maps. One of the boats in Fareham Creek, just down the road from where I live has reflected perfectly into the camera. Looks quite striking.
Sunjuice!
by Daniel on Mar.16, 2009, under Blog
The sun shining through my bedroom window is now enough that it is starting to wake me in the morning before my alarms (yes, all five of them) go off. So I thought I’ll pull out that solar panel I so ingeniously bought during the winter!
Even at the time I took that picture, it’s not terribly sunny but I was getting 11.3 volts out of it, in direct sunlight I got 20-odd so I’m quite happy with it.
Big-ass battery, heavy-ass battery too. Charge controller on top (duct-tape again), nothing hooked up to the load at the moment, need to get me some car-stylee sockets and a MacBook Pro charger. Though I may grab an inverter and give it a go with a few things. But I’d rather not take 12vdc turn it into 240vac (or whatever it is now) just to turn it into 17.5vdc!
In the mean time it’s just been powering a breadboard, again duct-taped to it, with a 5v regulator powering my Arduino via a spare USB PCI backplate I had knocking around. The Arduino just slowly fades a green LED via the successfully constructed Power LED driver circuit. Only, I don’t have an appropriate R3 (see diagram on previous link) for my Luxeon stars (d’oh) so it’s a bit superfluous at the moment. But all that together, Rube Goldberg would be proud!
EYEBROWS! :D
by Daniel on Feb.09, 2009, under Blog
I love this one! It’s brilliant! Anyone who hasn’t seen it yet needs to do so now…
Snow!
by Daniel on Feb.02, 2009, under Blog
It snowed last night!
Dougie enjoyed the snow too!
Alexie made snowballs. Her college called a snow day, alright for some.
Happy Orbit
by Daniel on Jan.07, 2009, under Blog
Haven’t posted in a while, just thought I’d pop my head out and wish the interweb a happy new orbit! (I like the word orbit, it doesn’t get said enough)
Not been up to much myself. Did nothing over xmas/new orbit, pretty low key.
I’ve got an Arduino and an range of different components on the way from various places. I got me 16x 1W White Luxeon LEDs for a tenner (horray ebay!) which was nice. Unfortunately they’re just sat in their packet at the moment, nothing to drive them with. If I could find that redundant USB lead that’s knocking around, I would’ve already blinded myself with them by now, but not yet.
For now I’ll start out with LEDs and Pulse Width Moduation to dim them. I’m very fond of LEDs, so any kind of LED-based lighting is just happy-go-luckly-magic-land-of-horray for me.
A couple of clickies relevant to my unfiltered ramble:
http://www.cpemma.co.uk/555pwm.html - Simple enough circuit for PWM using a 555 timer.
http://www.instructables.com/id/ECM4Q6NH9IEWOF32MJ/ - High power LED driver circuit for MCUs and the like.
I also came across this chip (Tremendous Geekery: http://focus.ti.com/lit/ds/symlink/tlc5940.pdf) in a couple of Instructables and there appears to be an Arduino library for using it. So I may have to get me one (and spare) of those to play with.
When I’ve got something working I’ll post a vid. Everyone loves videos of blinkylights right?
Anyway, that’ll do for now - laters.
WP Theme that doesn’t display comments???
by Daniel on Nov.12, 2008, under Blog
I was using the Blass2 theme from the WordPress theme site, and apparently it doesn’t display comments properly… what is the point in that???Now I need to find a new theme.
Hampshire Web Developers - Introduction
by Daniel on Nov.12, 2008, under Blog
Hey all! Just a note to say, I’m a Web Developer and I live in Hampshire. I work with Rich and Dave, who told me about the idea. So, hello.Currently I work mainly with PHP5, MySQL with a view to playing with PostgresSQL. I’ve been using a lot of XSLT lately, XML rocks. Also on my to-do list is some jabber fun, not sure when I’m going to get on my arse and do something about it though. I’m very interested code structure, how data moves around different systems and the separate layers within a system. I’m someone who sees their code as their art, and it is art. Or at least it should be. Haven’t really been up to much of note lately, as you can probably see. But I do have a bunch of LEDs and batteries on standby. My solar panel arrived the other day, still waiting on the charge controller. As I write this though the thought dawns on me that I haven’t really chosen the right season for that, never mind. But expect stuff along those lines along with the possible exception. Anyway, I’ll be off, need to perform cat-maintenance…
Good Advert
by Daniel on Aug.15, 2008, under Blog
I like this advert. I’m not overly keen on the car. It could look better.
But I really like the advert. I’m not sure what it is about it. A collection of all sorts of interesting boring objects. Quite fascinating.







