Archive for the ‘Programming’ Category

ModelForm developments

Monday, October 20th, 2008

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

How to CSRF protect all your forms

Thursday, October 16th, 2008

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

Zend Framework - good for beginners or not?

Tuesday, October 14th, 2008

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

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

Sharing authentication over multiple sites / Single sign-on

Thursday, September 25th, 2008

At The Group, we're developing some web applications that needed to use the same user database. The applications were originally being developed with separate login for each, but I decided it would be better to share the login code across them. I investigated some ways to achieve sharing a single login ...

You should know at least three languages

Saturday, September 20th, 2008

I think a good programmer should know at least three languages: English C or C++ A scripting language with dynamic typing Why?

Generic collections in PHP

Wednesday, September 17th, 2008

Today while reading PHP::Impact's refactoring guideline post I was reminded about collections. As you probably know, arrays are very flexible in PHP and probably a good choice for many data storing tasks. Strictly typed languages usually use "generic" collection classes instead of arrays. They are kind of like PHP arrays which ...

Theory vs. Practice in coding

Tuesday, September 9th, 2008

When working on a project, I sometimes find myself stuck - thinking about some implementation detail, such as how to tell my admin-module which other modules are installed in my CMS (but that's another story) - and being stuck, unable to get anything done, just thinking of the problem at ...