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?

Read More

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;

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)
     ->setHeader('Content-Type', 'application/zip')
     ->setHeader('Content-Disposition', 'attachment; filename="some.zip"')
     ->setHeader('Content-Length', strlen($file));
 
//If using Zend_Layout, we need to disable it:
$this->_helper->layout->disableLayout();
 
//Disable ViewRenderer:
$this->_helper->viewRenderer->setNoRender(true);

In closing

As mentioned in the comments, this approach may not be suitable especially if you deal with very large files. I recommend checking out this post about using mod_xsendfile with PHP, as it solves the issues associated with sending files “manually” through PHP.

Static/Dynamic typing sweet spot

Tags:

Commenter TurboC linked an interesting talk about the future of programming languages. This got me thinking about something I had thought about before:

It seems that PHP has moved a bit towards static typing, and languages like C# seem to be implementing some dynamic features. Are we going towards a “mixed” language with static and dynamic typing? What’s the “sweet spot” between completely static (like C++) and completely dynamic typing (like Python)?

Read More

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:

  1. Create a PDF template
  2. Insert data to template with Zend_Pdf
  3. Profit $$$

Since this is a quite repetitive task, let’s also create a PDF generator class to help us. In case you don’t have Zend_Pdf, just download Zend Framework to get it.

Read More

Let’s Rickroll MTV Europe Music Awards 2008!

Tags:

Okay so this is totally off the usual topics I guess, but this is too awesome to let it fail!

Rick Astley has somehow managed to get into MTV Europe’s Music Awards 2008 gala in the category Best Act Ever. I suspect /b/ had something to do with this, but…

I urge everyone to vote for Rick and tell everyone else to do the same! It’ll be the biggest rickroll ever if it succeeds. If the site appears slow or not working, try choosing some other language from the bottom right corner.

Windows Remote Desktop + Live FolderShare = Ultimate combo?

Tags:

I’m a frequent user of Windows’ remote desktop feature. It’s a stellar remote control solution: It’s incredibly fast, almost like sitting on the remote PC, and has features like bringing over the clipboard and even sounds from the controlled computer.

Much better than VNC, really. VNC is painfully slow compared to it, even over multi-megabit internet connections.

There is one feature Windows Remote Desktop is lacking, though: File sharing between the computers.

I had recently heard about Microsoft’s Windows Live FolderShare, a synchronization service. Now, you might not initially think it’s a good option, it is Microsoft afterall… but Microsoft has been doing a fair share of good applications lately: Visio 2007, Visual Studio 2005+, even the new Windows Live Mail is actually very nice to use, despite not working in some browsers. Oh, and isn’t Microsoft the company which makes Windows, so their solution for syncing might actually integrate into it pretty nicely…

So I installed FolderShare on my laptop and desktop (naturally through Remote Desktop ;)), and I have to say it was a breeze. I only had to log in to FolderShare, set up a shared folder on the laptop and set up the desktop to sync to it as well – all very quickly and easily set up, didn’t even require a reboot. Syncing a couple of files I wanted to move was a breeze as well.

If you’re a Windows user and have multiple PC’s (or Mac, FolderShare supports Mac’s too), I would most definitely recommend checking FolderShare out.

Sharing authentication over multiple sites / Single sign-on

Tags:

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 page over all these applications:

  • A shared login library
  • A custom CAS style setup
  • OpenID

They all have some advantages and disadvantages, though…

Read More

Generic collections in PHP

Tags:

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 the programmer can tell which type of items to accept. This is of course only natural when you don’t have dynamic typing, but it can also be useful for avoiding programming errors, so I thought I’d try making a basic generic collection class in PHP…

Read More