A relatively common task when working with forms is filling select boxes or checkbox and radiobutton lists from a database. It’s not very tricky to query a database, and fill a Zend_Form element’s possible values from the resultset, but it can be quite boring and extraneous code…
We could also create an element which we can give some SQL, and it’ll fill itself automatically! This way you can even define database-backed elements in XML or INI configuration files.
Sending files better: Apache mod_xsendfile and PHP
I have previously written a quick post on making files downloadable through PHP scripts. The example in the post reads the file itself into a variable, and as pointed out in the comments, it’s not necessarily a very good idea especially if you deal with large files. Recently at work, we needed a reliable way to send files to users’ …
Using Prototype Property in JavaScript
The following topics are discussed in this article: Every function has a prototype property and it contains an object, Adding properties to the prototype object, Using the properties added to the prototype, The difference between own properties and properties of the prototype, __proto__, the secret link every object keeps to its prototype, Methods such as isPrototypeOf(), hasOwnProperty(), and propertyIsEnumerable()
Handling errors in Zend Framework
In Zend Framework based applications, error handling is typically done using the error controller, but there are different ways to send the execution to it – some better than others. Let’s look at some ways to trigger the error controller and how to have it handle different error conditions.
Creating a simple abstract model to reduce boilerplate code
In a usual scenario involving models in PHP, you will have some repeating things: You will usually need getters and setters for the model’s properties, you will need to be able to construct the model from an SQL query or such, and you’ll also need to write SQL queries for the models. While none of this is very complex, it’s …
Ajax, high latency and user experience
Most of us probably have used at least one website which bases some major functionality on Ajax. But have you ever used a such site, done something, then moved on to another page, only to come back later to realize what you just did was never saved? What happens to XMLHttpRequests in a high latency situation, and how to deal …
Closures coming in PHP 5.3 and that’s a Good Thing
PHP 5.3 will be introducing closures to PHP. Closures, also known as anonymous functions, will allow you to declare functions “inline” and store them in variables. While the syntax may seem a bit weird compared to how it is in languages like JavaScript, closures will be a useful addition to the language
Zend_Acl part 3: creating and storing dynamic ACLs
In this third post of the series, I’ll talk about using dynamic ACLs: How to store an ACL in a database, and construct it from there when needed. We will first look at a simple example with users and pages, and then we’ll have a more complex example, involving building a much more complex ACL with inheritance, role types and other stuff.
Practical uses for reflection
You may have heard about the reflection feature in PHP. Simply put, it’s a way to get a list of methods in a class, a methods parameters, or other “internal” things like that. But how is this actually useful for any common task in application development?
Functional programming and Haskell
I’ve been learning some Haskell for fun. Haskell is a functional language, so it’s quite different from other languages I know like PHP or C#. One of the main “ideas” of functional programming is immutability – in other words, you can’t change the value of a variable after you’ve defined it. How do you deal with this? Also, Haskell has …