 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
DevShed: Using Directory Iterators to Build Loader Apps in PHP
by Chris Cornutt July 06, 2009 @ 10:17:11
DevShed finishes off their "loader" series of tutorials today with this eighth part focusing on the use of Directory Iterators.
Here's where the SPL comes in, since it's possible to use a combination of its "spl_autoload_register()" function and its RecursiveDirectoryIterator class to refactor the method in question and make it shorter and tighter. In this final chapter of the series I'm going to improve the loader class developed in the previous one by incorporating some of the aforementioned SPL functions and classes.
They change up their code to use a RecursiveDirectoryIterator inside of their __autoload to remove their custom recursive code.
voice your opinion now!
tutorial autoload recursive iterator directory spl
Tiffany Brown's Blog: Simple pagination for arrays with PHP 5
by Chris Cornutt December 15, 2008 @ 08:48:20
Tiffany Brown has a quick tutorial on a pagination method she's come up with for splitting out array contents over multiple pages.
While working on a recent project, I had to build a feature that displayed a list of files available in a directory. A simple way is just to use scandir() and a foreach loop to spit out a pretty list. There's a small problem though: long lists aren't all that user friendly. I decided instead to paginate the results. Here's one way to do it using PHP 5.
Her method reads in all of the (valid) files from the directory, assigns them to an array and uses the array_chunk function to split them up into groups on five. These groups can be easily looped through and displayed out as links easily.
voice your opinion now!
pagination php5 arraychunk directory files
PHPro.org: SPL Autoload
by Chris Cornutt November 14, 2008 @ 09:31:48
On the PHPro.org website, Kevin Waterson has written up an introduction to the handy autoloading functionality that comes with PHP5 releases - the __autoload method from the Standard PHP Library (SPL).
The SPL __autoload() method is one of the Magic Methods supplied in PHP. The __autoload method is called whenever a class is instantiated and will load the classs the the first time it is called. No longer is include(), require, include_once() or require_once needed as the SPL autoload takes care of this interally.
He looks at how you can use it to load a directory of classes, how to use multiple autoloads in a single script and how to use it with interfaces to register a loader and include it as needed.
voice your opinion now!
spl autoload standardphplibrary tutorial introduction directory register multiple
NETTUTS.com: Scanning Folders with PHP
by Chris Cornutt November 13, 2008 @ 14:18:28
The NETTUTS.com site has posted a new PHP-related screencast that covers a simple script to scan over the contents of folders in PHP. To illustrate, they create an image gallery script that mirrors the filesystem structure.
Let's imagine that you want to build a page that will display snapshots of your latest work. [...] In such instances, the best solution is to make PHP scan your "portfolio" folder and dynamically create the code for you. If you want to update your page with a new snapshot, all that you need to do is drag the image, and its respective thumbnail, into the appropriate folders - and PHP will do the rest. Let's build it now!
The screencast comes complete with the entire source and a link to a demo to show the end result.
voice your opinion now!
scan folder filesystem directory tutorial photo gallery screencast
PHPImpact Blog: Scalable and Flexible Directory Structure for Web Applications
by Chris Cornutt August 11, 2008 @ 11:17:30
In this new post on the PHP::Impact blog, Federico looks at some examples of directory setups for web apps that can help to make them both scalable and flexible.
Designing a modular and component-based directory structure for your Web applications can seem like an easy task. If your system is small, it may seem logical to go with the simplest design possible, but if there's anything more time consuming and complex than developing a new directory structure design, it's trying to redesign an existing system that wasn't developed with growth in mind.
He breaks it up into a few different topics that can be applied where needed to keep the application in check:
- Consistency
- Scalability and Flexibility
- Single Application
- Multi-application
- Naming Conventions
- Versioning
- Proposed Structure
voice your opinion now!
scalable application flexible directory structure
Builder.com.au: How do I...recursively scan directories with PHP's DirectoryIterators?
by Chris Cornutt June 18, 2008 @ 07:55:21
Builder.com.au has a new tutorial posted today talking about the use if Iterators (from PHP's SPL) to recurse down through directories on your local drive.
One of PHP5's most interesting new features is the addition of Iterators, a collection of ready-made interfaces designed to help in navigating and processing hierarchical data structures. These Iterators significantly reduce the amount of code required to process an XML document tree or a file collection.
They give three examples - two basic ones showing a simple use of the DirectoryIterator and RecursiveDirectoryIterator and another slightly more complex one showing how to get information from the recursive iteration as it goes down.
voice your opinion now!
directoryiterator iterator recursive directory example
Lars Strojny's Blog: New magic constant in PHP 5.3
by Chris Cornutt February 22, 2008 @ 15:02:00
In this new blog post today, Lars Strojny talks about a new magic constant that will be joining its brothers in the upcoming PHP 5.3 release - __DIR__.
In PHP 5.3 there will be another magic constant __DIR__. [...] To allow this, the internal function php_dirname() has been moved in the Zend Engine and is now called zend_dirname(). Nevertheless an alias still exists.
__DIR__ will join the other constants (like __LINE__ and __FUNCTION__) to help give the currently running script a little introspection for things like its filename, what class it's currently in and now, what directory the file currently lives in.
voice your opinion now!
dir magic constant directory php5 new
|
Community Events
Don't see your event here? Let us know!
|