Lorna Mitchell has posted an article to the Ibuildings blog looking at the Zend_Paginator component of the Zend Frameworks, some of her first impressions.
The idea of this module is to allow collections of data to be paginated. It takes the set, restricts the results, and can also generate the page numbers you need to move around between the resulting paginated data. Basically it saves me writing the same pagination code multiple times and then having to fix the bug where the last result on the previous page appears on the next ... all this has been thought of already.
She shows how it works with a simple example - paginating results from a database table, setting the count per page and the current page number. This object is pushed out to the view and rendered (in her case) via a Smarty template.
In a new entryKnut Urdalen looks at something that some PHP developers might have forgotten about - the return value of the include statement.
PHP never stops surprising me. I just found out that you're able to return values from the inclusion statements (require, require_once, include and include_once) through an example of Zend_Config.
His example puts an array of values inside the include file with a return statement. This script is included from another and, because of the return, the array data is passed back out into a waiting variable set equal to the include statement.
The NETTUTS.com blog has a new screencast posted showing how to create a simple thumbnailing script you can use in any application (like an image gallery).
In this week's screencast, I'll show you how to upload files and then have PHP dynamically create a thumbnail. Whether you're building an ecommerce site, or just a simple gallery, these techniques will absolutely prove to be useful. If you're ready for your "spoonfed" screencast of the week, let's get going!
The post also includes all of the code and HTML that you'll need to get it up and running (very cut and paste-able).
In a new tutorial from the IBM developerWorks site starts off a new series looking at creating some games, from start to finish.
PHP is an easy-to-use, easy-to-learn, widely accessible programming language. It's well suited for developing simple scripts you can use to help you in all kinds of games. Whether you play simple pen-and-paper games by yourself, complex tabletop role-playing games with a group of people, or online games of any kind, this series will have something for you. Each article in this "30 game scripts you can write in PHP" series will cover 10 scripts in 300 words or less (3d10 stands for "roll three 10-sided dice") simple enough for even a beginning developer, but useful enough for a seasoned game player.
The ten scripts they walk you through are things like a die roller, a name generator, a deck builder/shuffler, a poker dealer and a crossword helper.
When it comes to code coverage and untested parts of your application (unit tested, of course), Zoe Slatteryhas a suggestion that could make your life easier anyway - follow the core PHP developer's example:
But - there is another way, and as usual the PHP core developers are showing us the way. The fastest way to improve percentage of code covered is to REMOVE UNTESTED CODE! Accordingly we saw the test coverage of PHP 5.3 increase from about 55% to a little over 70% over the summer of 2008. At the same time the lines of code in PHP dropped by about 50KLOC. How can this be?
Removing untested code (that's not needed anyway) can reduce unit testing times dramatically and can help you keep your code clean, lean and simple for the upgrades that will come later on.
New on the SitePoint "Web Tech" blog today is a post by Craig Anderson about friendlier passwords.
One aspect of web applications which is almost always overlooked when it comes to accessibility is how easy any randomly generated string might be to read. If you're lucky enough to have near perfect vision and have no learning or cognitive disabilities such as dyslexia, you mightn't suffer from any problems reading randomly generated strings, but for many users distinguishing between zero and upper-case Os, ones and lower-case Ls, and even the letters b and d can be difficult.
He includes a simple little PHP script that pulls letters and numbers from a pre-defined "friendly" array that can be read more easily by those with some sort of visual issue. Obviously, the results would be less secure than some other methods (only so many to go around) but its still a wide enough range for most common uses (around 17 million passwords).
Continuing on from a previous post, the PHP in Action blog takes another look at their suggestions on "beautiful code" with some responses to the previous post.
I got some interesting comments to my previous post on "beautiful code". Some were pretty strong disagreements. So am I wrong? Did I get carried away? Did my critical faculty go on vacation somewhere nice and sunny? [...] My main point is that it's close to plain English. Not everyone agrees that that's a good thing, but I argue that we're built (genetically wired, in fact) to understand natural languages, not program code.
He reasons that code should be easier to understand than just a bunch of random functions and parameters jumbled together. He thinks that it should read more like a human could understand rather than just the machine. With function names like "assertThat" and "hasSelect", it does make it easier to follow.
The Flex and Air blog has posted about a tool that can be used to jump-start your Zend_Amf powered application - CRUDdy Buddy.
CRUDdy Buddy is an AIR application I created to generate the code necessary to get started on a Zend_Amf project. It creates all of the PHP necessary, along with ActionScript classes and <mx:RemoteObject> tags you can paste into your Flex or AIR application.
They have a video on Vimeo showing it in action. You'll need the Adobe AIR runtime to be able to use it, but that's a simple and quick install. There are versions for both Mac (using Mac-specific fonts) and Windows/Linux (using Arial). You can download a PDF of the documentation here.
Rob Allen has made a new post today showing off Action Helpers in the Zend Framework.
When you have some functionality that needs to be shared across multiple controllers, one method is to use action helpers. Action helpers are very powerful and contain hooks to automatically run when you need them too, but you can ignore all that if you don't need it.
He includes how to set up the "helper broker" pointing it at your helper files and a simple helper that multiplies the input times two. This helper is then applied inside of his example action (in an IndexController, of course) and assigned to an output variable in the view. He's included a code download as an example.
On the PHPBuilder.com site today there's a new tutorial continuing in their Oracle theme about using the ADOdb libraries to access the database from your application.
Last week we discussed the use of the OCI8 extension and connection methods for using ADOdb to connect to an Oracle database. This week we'll delve further into the ADOdb library and will disect some example code to get you up to speed!
He gives an overview of some of the functions needed to make the connection and fetch results from a simple query. Some sample code and explanation is also included.