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.
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.
David Otton has shared a discovery he's come across in his development - user-defined classes are not derived from stdClass.
Many OO languages have the concept of a single base class from which all other classes are explicitly or implicitly descended. For example, Ruby, Java and .NET all have Object. It's a very common belief that PHP implements stdClass as a base class for all objects, but this is in fact not the case.
He illustrates with a code example showing the results of calls to instanceof with a normal user class and one that extends the stdClass object.
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).
David Otton has a new neat PHP trick posted today - assigning references to global values.
What follows isn't so much a PHP trick as a fix for something that really should work, but doesn't. Although the manual implies that the behaviour described below is specific to Zend Engine 1, all my tests were performed against Zend Engine 2.2, PHP 5.2.5.
His example compares making a new stdClass both with and without a reference on the it and var_dumps out the result. The method with the reference fails silently, however and isn't able to correctly assign it to the global. He recommends a work-around though - setting it directly to the $GLOBALS superglobal.
The symfony blog has a new post spotlighting one of the new features of their 1.2 release - updates to its Doctrine functionality.
A lot of awesome stuff has been added recently to the next major symfony release, 1.2. Fabien has worked very hard to add without a doubt the most sophisticated features of any PHP framework that exists today. Not only are they nice features but he has implemented them in a OO way so that it is easy for me to implement the same features with another ORM, Doctrine. All this is done with very little work by me. So, give a big thanks to him if you enjoy this.
Included in the post is a real-world example showing how to use the symfony command line to build out an environment and create connections to the articles, categories and authors tables.
Padraic Brady has revisited the older parts of his blog tutorials in a new post today (parts one through eight of the series) in anticipation of number nine to be released soon.
By now many readers are aware of the all-consuming mega tutorial I've been writing illustrating one method of writing a blog application with the Zend Framework. What started initially as a possible book project switched over to a more open process of blog posts with a future PDF version as a standard reference project. Back during the Summer I had to put the series on hold, but it's time to get kicking again.
A list of links to the previous parts is included as well as a brief look forward at some of his plans for the series (including a method to convert from the post's format into Docbook for easy translation into HTML or PDF).
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.