 | News Feed |
 | Jobs Feed |
Sections
|
| feed this: |  |
Debuggable Blog: How to bend Cake's Modelfind() method to your needs
by Chris Cornutt June 23, 2008 @ 12:08:32
New on the Debuggable blog, Tim Koschutzki has posted a method to get the fund() method in the CakePHP framework's models to bend to your will.
CakePHP allows you to use your own "find-types" for the Model::find() methodology. Those of your who are familiar with the find() method know that there are currently four types in the core: 'list', 'all', 'first' and 'count'. However, sometimes it is nice to specify your own type.
He shows an example of the end result - a find() call with a custom type that automagically gets translated correctly. His script overrides and enhances the usual find call in an extended object (extended from AppModel) that uses a switch/case statement to define the custom types and their find() search calls.
voice your opinion now!
cakephp framework find custom type model switch case
SitePoint WebTech Blog: Give Your Visitors a Rough Time
by Chris Cornutt March 06, 2008 @ 08:44:00
In a new post to the Web Tech blog over on SitePoint, Toby Somerville has posted something he calls "RoughTime" - his method for displaying a more "human friendly" output of a timestamp.
When asked the time, we generally don't need to be military accurate with our response [...] we generally communicate the approximate time. i.e. 'its nearly ten' or 'its just gone half past three'. Yet on the web, time is generally shown as '12:24:13 AM', or similar '" not very visitor friendly.
His RoughTime uses two switch statements to map the hour and minute values to different strings. For example, minutes between 15 and 20 become "quarter past" and the hours are changed over from numeric versions to their word counterparts.
voice your opinion now!
roughtime switch approximate time hour minute translate
Rob Thompson's Blog: Switch vs. If
by Chris Cornutt February 01, 2008 @ 14:28:00
Rob Thompson has posted about some simple benchmarking he did comparing the speed of a series of "if" statements versus one "switch" with multiple cases.
I got curious about which is actually more efficient at matching a random integer with a set of conditionals. So, I setup a script to create a set of large scripts to test the speed of these different constructs. Using the 'time' command, I measured the speed at which the condition could match a random number.
His results found that the switch statement is generally more than 2 times as fast at matching a simple integer. His tests, however, didn't go through much more than this simple test. It'd be interesting to see what it would do with something more complex (like longer strings or handling the result of an evaluation inside the definition of the switch().
voice your opinion now!
switch if evaluate benchmark elseif compare
DevShed: The Switch Statement and Arrays
by Chris Cornutt January 07, 2008 @ 12:50:00
DevShed continues their series looking at some of the fundamentals of working with PHP in this new tutorial posted today. It looks at one of the flow control statements the language has to offer and a very useful data structure - the switch statement and arrays.
In our last exciting adventure (back in early November), we braved crocodiles, ravenous editors, most of the PHP statements, and beginning loops. In this edition we'll cover the final statement, the Switch, and discuss arrays. So sit back, order your R2D2 robot to bring you a cold, frosty Jolt Cola, and let's get cracking.
They start with a simple example of a switch statement (to echo out strings) and follow it with a detailed description of the different sorts of arrays - numeric indexed, associative and multidimensional versions.
voice your opinion now!
tutorial switch flow control array numeric associative multidimensional tutorial switch flow control array numeric associative multidimensional
Soledad Penades' Blog: Signs your PHP needs refactoring
by Chris Cornutt June 05, 2007 @ 16:26:00
As mentioned by Ed Finkler, there's a list of signs your PHP needs refactoring from Soledad Penades.
I have had to go through a php application recently which has given me more than one headache and has required me to use all my possible patience. While working with it, I thought This is good material for an article, so that nobody else does the same in the future, and nobody else will need to experience the same displeasure as I have had to.
So here are the signs your PHP application needs a serious refactoring, right now
Included in the list are things like:
- Uses global variables
- Everything's an array
- The neverending switch
- Interface inconsistency
It hits on one of the thing that bugs me too, the problem of "Brackets galore" - so many subarrays that you have to resort to three or more sets of bracketed keys to get to the value you want. It's bad enough trying to follow someone else's code without having to "trace down" an array to figure out which of the values they're talking about.
voice your opinion now!
refactoring global bracket duplicate switch interface inconsistent refactoring global bracket duplicate switch interface inconsistent
Matthew Weir O'Phinney's Blog: Cgiapp2 Tutorial 1 - Switch Template Plugins at Will
by Chris Cornutt June 06, 2006 @ 05:47:28
Right on the tails of a new release of the Cgiapp set of libraries, Matthew Weir O'Phinney has posted a first tutorial in a series covering its usage. In this tutorial, he looks at a creating a "template switcher" for Cgiapp2-based applications.
Cgiapp2 implements a new callback hook system, which is basically an Observer pattern. Cgiapp2 has a number of registered hooks to which observers can attach; when a hook is triggered, each observer attached to it is notified and executed.
Why all this talk about hooks? Because in Cgiapp2, the various template actions -- initialization, variable assignment, and rendering -- are relegated to hooks. For simplicity's sake, and for backward compatibility, you can use the functions tmpl_path(), tmpl_assign(), and load_tmpl() to invoke them; you could also use the generic call_hook() method to do so, passing the hook name as the first argument.
To make it simpler for developers to access this templating system, Matthew created the Cgiapp2_Plugin_Template_Interface, a standardized interface for the template plugins. It's this interface that he demonstrated an example of, giving only a few lines of code (all that's needed) to switch between Smarty and Savant templating systems.
voice your opinion now!
php tutorial cgiapp2 template switch plugin interface php tutorial cgiapp2 template switch plugin interface
Kian Hui Teo's Blog: Switching between PHP 5.1.x and Zend Core for Oracle
by Chris Cornutt May 22, 2006 @ 17:46:32
Via this post from Christopher Jones we learn about Kian Hui Teo's blog post talking about making the switch between the normal PHP 5.1.x installation and the Zend Core for Oracle.
This situation arises as I had installed Zend Core for Oracle (ZCO), and I wanted to try out some PDO functions. As ZCO comes with PHP 5.0.5, I was stuck, and PDO is only included from PHP 5.1.x onwards, I had to install PHP 5.1.x on my Windows box so that I can play with PDO. The assumption is that we have ZCO installed and working with a Apache2 server. I share the steps here on how to install another version of PHP so that it will co-exist peacefully with ZCO.
The post outlines a process to allow both the Zend Core and a normal installation of PHP 5.1.x to live peacefully (and still be able to switch from one to the other at any time). It's actually a relatively simple ten-step process to follow, especially if you've had much experience with installing PHP from scratch. When complete, you can start up one or the other, making it easy to test scripts in both or to just use the functionality in one (as he needed with PDO).
voice your opinion now!
php zend core oracle php5 switch one machine pdo php zend core oracle php5 switch one machine pdo
|
Community Events
Don't see your event here? Let us know!
|