Complex custom elements in Zend_Form

Tags:

I’ve sometimes needed custom elements in forms – say two fields for inputting two numbers. For something simple like that, adding two separate elements usually suffice, but when one of my clients wanted a field with multiple checkboxes, but only specific pairs could be selected, it started getting too complex. Until then, I had kind of avoided making those custom …

ModelForm developments

Tags:

I’ve been reworking the ModelForm class for ZF a bit. Earlier this year, I discussed porting it to use Zend_Db_Table with Matthew Weier O’Phinney, for using it with Zend Framework. I initially had done some checking on Zend_Db_Table, and some small code changes to modify the class to use it instead of Doctrine, but I ran into some issues. Now, …

How to CSRF protect all your forms

Tags:

CSRF, or Cross-Site Request Forgery, is a vulnerability very common in websites. In short, it means that if you have your site at foo.com, and an attacker at badguy.com can display a form similar to one of your site’s, and make users on his site submit the forms on your site, possibly without their knowledge. This can be dangerous, especially …

Zend Framework – good for beginners or not?

Tags:

I’ve heard some inexperienced PHP programmers say that Zend Framework is confusing to them. Until today, I have agreed: Zend Framework has a lot of classes and some of them are quite complex (such as Zend_Form). But does that actually make it more difficult for inexperienced programmers than other frameworks?

PHP tip: How to make a file downloadable through your script

Tags:

This seems to be a relatively common question on #zftalk nowadays, so here’s a quick wrapup! The traditional plain-PHP way $file = file_get_contents(’some.zip’); header(’Content-Type: application/zip’); header(’Content-Disposition: attachment; filename="some.zip"’); header(’Content-Length: ‘ . strlen($file)); echo $file;$file = file_get_contents(‘some.zip’); header(‘Content-Type: application/zip’); header(‘Content-Disposition: attachment; filename="some.zip"’); header(‘Content-Length: ‘ . strlen($file)); echo $file; The Zend Framework controller way //this is inside an action in one of …

Making a PDF generator class using Zend_Pdf

Tags:

There are some expensive libraries that you can use to generate PDF files… but why bother with them, when there are good free alternatives like Zend_Pdf? In three steps, you can generate a fancy report: Create a PDF template Insert data to template with Zend_Pdf Profit $$$ Since this is a quite repetitive task, let’s also create a PDF generator …

Zend_Form decorator tips

Tags:

It seems a lot of people are struggling with Zend_Form decorators. They want to know how to modify the markup, but they can’t figure out how to do it with the bundled decorators or how to write their own. Since I’ve done some decorator-stuff myself, I thought I’d share some tips on making the output a bit nicer. For example, …

View inheritance and “blocks” in Zend_View

Tags:

Some frameworks like Django and PRADO have the concept of view inheritance, or a “master page” like in ASP.NET. Essentially it’s a similar idea as Zend_Layout is in Zend Framework, but the difference is that you can define the master/parent view inside the view itself. For example, in Django {% extends “base.html” %} would make the current template extend “base.html”, …