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

Friday, October 10th, 2008

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; The Zend Framework controller way //this is inside an action in one of your controllers: $file = file_get_contents('some.zip'); $this->getResponse() ->setBody($file) ...

Zend Framework components as separate zips from the main distro? Sure!

Monday, October 6th, 2008

Did you ever want to use just a single component from Zend Framework, but couldn't figure out which files you needed? Well, here's a solution: Zend Framework packageizer script! Just pick the class you want, and you'll get it and all its dependencies in a nice zip file for you to ...

Making a PDF generator class using Zend_Pdf

Saturday, October 4th, 2008

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 ...

Zend_Form decorator tips

Thursday, August 7th, 2008

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 ...

View inheritance and “blocks” in Zend_View

Friday, August 1st, 2008

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 ...

Making working with DB records easier with a controller helper

Saturday, July 5th, 2008

The other day I noticed a pattern that repeats quite much in my code: Take a parameter from the request, such as id Query the DB for a record that matches the param Redirect or throw a 404 exception if record was not found Why do all this, when it could be simply a ...

Ideas for testing Zend Framework apps

Thursday, July 3rd, 2008

Here are some ideas I was thinking of for making testing Zend Framework (and Doctrine) based apps nice and easy.

Zend_Form’s from Doctrine models: Part 2

Wednesday, June 4th, 2008

Previously I wrote about my class for generating Zend_Form forms from Doctrine models. This time, let's look at some more usage examples and how it works internally, to make it easier for you to utilize it. Edit 10.10.2008: Updated the post to reflect some minor changes in the CU_ModelForm class

Autogenerating forms from Doctrine models

Monday, June 2nd, 2008

In a previous post I mentioned how Django's model forms are awesome. I really like the idea of being able to generate forms automatically from models - I mean the models already should contain most of the data you'd need: the fields, field types and how they will be stored. Since ...

Django = Awesome

Friday, May 16th, 2008

So in the lack of anything "useful" to post, and in the attemps to at least post something interesting, I shall dedicate this post to talking about what makes Django such an awesome framework! I'm going to compare it to Zend Framework, as it's the framework I'm most familiar with.