PHP-Coding-Practices.com: Making CakePHP's Pagination work with Model::expects()
16727
Tim Koschuetzki has posted a new CakePHP-related tutorial to the PHP-Coding-Practices.com website today showing a method that gets the framework's pagination to cooperate with a Model's expects() method.   Making CakePHP's pagination work together with Mariano Iglesias' expect functionality seems to be impossible. The expect()'ed associations are only used in the paginator's findCount() call, but not in the findAll() call which actually retrieves the results. Come on join me and find out how to fix this.   His solution involves the creation of a custom pagination method that ends up calling the Paginator helper with some special parameters (replacing the non-cooperative defaults).
727879
On Cesarodas.com, Saddor as created a simple class to help with caching information in a PHP application - specifically when it comes to capturing output (like HTML generated for the page).   Usually we need to find a way to help php to reduce the number of query to a  database, because as a friend told me: "Most of time php is awaiting for a database to response". And that is wasted resource (time, processor, main memory). The developer need to find a way to store some pages until it changes or something like that. There are many cache classes over there, but exist many problems, I will focus on two problems. Implementation and concurrence.   His gCache class uses capture/endcapture methods to define where the content starts and ends and, once the information is stored, checks with a valid method and echoes the content if it's been cached. An example of the class in action is also included.
129211
Chris Hartjes has posted a quick example of a useful method for CakePHP developers - how to test components.   Using the test suite is actually quite easy: drop SimpleTest into your cake/vendors directly and you're ready to start writing your tests. Having written tests using SimpleTest before it wasn't going to be too hard for me to get them done. But there was one little problem: how do you test a component?   He includes an example of such a test, running it on his Email controller to try to send an email via SMTP.
285686
PHPBuilder.com has another in their series of excerpts from the Sams Publishing book "PHP 5 in Practice" today - a look at paginating results on a website.   When creating browse or search functionality on a website, you many find that you end up with more data than the page can easily display at once. In these situations it makes for a better user experience to give users only a certain number of results and then present them with options to see the next and/or previous pages.   The code listing is slightly complex, but it does provide a good, clear look at how to paginate the values in an array. They also explain a bit about the two functions that make it possible - http_build_ query and array_chunk.
576895
Here's what was popular in the PHP community one year ago today:Symfony Project: Book preview: read the Unit Tests chapterWebCheatSheet.com: Secure File Upload with PHPMichi Kono's Blog: The Best PHP Book Out ThereThe Bakery: Basic User Authentication in (CakePHP) 1.2.xPHPBuilder.com: Dynamic XML with PHPDavid Coallier's Blog: Zend_Db Without PDO part #3 (SVN Repository)?Community News: PHPLondon Conference 2007 AnnouncedMatthew O'Phinney's Blog: Overloading arrays in PHP 5.2.0Ilia Alshanetsky's Blog: 5.2.1 RC3 Released for testingJob Posting: Telio Telecom AS Seeks Senior Web Developer (Oslo, Norway)The Bakery: LightTPD and CakePHP setup in subdirectoriesJob Posting: Yahoo! Seeks Address Book Front-End Engineer (Sunnyvale, CA)HowTo Forge: PHP Programming BasicsJob Posting: Blue State Digital Seeks PHP/AJAX developer for politcal/tech consulting (Boston, MA)Zend Developer Zone:  AJAX Chat Tutorial Part 7 : Usability Improvements
247721
Continuing on from this previous post talking about Javascript in CakePHP applications, Felix Geisendorfer hands out more tips in this new blog entry targeted mainly at users of the jQuery Javascript library.   While the old solution was nice to manage the JS of a smaller application, this one is ment to structure your JS even in bigger projects. To make this possible I decided to go with a loose (MV)C pattern.   He gives an example of using a SiteController in connection with a CalendarController to help populate the information for the calendar.
57279
In a new post to his blog today, Felix Geisendorfer shares a method to make error handling in the CakePHP model functionality a bit more "beautiful".   Now I've written actions like the one above in the past as well. It's just that I've not had many MySql errors since I've switched to CakePHP. The Model class usually handles all the DB operations flawlessly and it's probably been over a year that I've written a custom MySql statement in my code somewhere. However, even CakePHP or, what's more likely, the database can fail or deny operations.   He shows some code snippets of what he sees as less beautiful versions of database insertion code, methods that either don't check the response/errors or make a messy job of it. His solution works by returning the result into a switch statement to check the results and handling it there (versus a series of ifs). There's a class you'll need to make it work (Common), but he shows how to use it and creates a simple "add" example with it and a new Controller to handle the request.
178429
On reading a message on the CakePHP mailing list about the web services built into the framework, Chris Hartjes decided to embark on his own look at what functionality the framework offers and how easy it is to use.   Might I add that until I tried this, I had never built a web service with CakePHP before. I found that by turning on the debug mode and actually following the instructions that were in the error messages (best undocumented feature of CakePHP if you ask me) I was able to build.   His code, while it worked, was one-upped by another's submitted to the mailing list (Samuel DeVore) so he's included that code in his example rather than the original. His example makes a TestController, an XmlComponent, and an XmlHelper to vary the output from a normal HTML to an XML format based on if "xml" is included in the path of the location.
766105
Felix Geisendorfer has posted a quick code snippet for the CakePHP framework that returns an array of the controller names in your application.   It's something I've heard people asking for in IRC quite some times by now and since I just needed it again I thought I might as well publish it here. I hope somebody out there finds it useful.   The code uses a Folder instance to grab all of the controller paths and push them into a $controllers array.
524053
Jonathan Snook has posted about a method he's using to make the creation/use of static pages in a CakePHP application (or website) simpler.   Traditionally in a CakePHP application, to do static pages you have two options: use the built-in Pages controller or set up an empty action in a controller.   Feeling that neither of these two options met how he wanted things to work, Jonathan (and Nate Abele) developed a class that extends the error handler in the CakePHP framework to handle "missing" actions and controllers. This means that, if an unknown controller/action combo is called, this script will check in its correct location (in the structure of the site) and try to find it to render it.
651804
On the Spindrop Blog today, there's the series wrapup for their look at using the Zend Search Lucene functionality inside of a Symfony application.   This is part of an on going series about the Zend Search Lucene libraries and symfony. We'll pretty everything up when we're done. We now know how to manipulate the index via our model classes. But let's actually do something useful with our search engine...let's search!   This quick post shows how to initialize the object and run the find() on the data and fetch out the results. They even work the script so that, if the index for the search isn't there, it generates it on the fly, then makes the search.
15606
On The Bakery today, there's three new examples of how the CakePHP framework was used to create three very different types of sites - PremierMarinas.com, ScienceHack.com and a simple iPhone-compatible application.   In the first article they describe how they built a "powerful, full featured CMS" to allow their customers to login and work with their personal information. It included the use of JSON messaging and the use of dynamic libraries. The article for the second site talks about the creation of a search engine for science videos to provide a more reliable resource for fellow video enthusiasts. He talks about what all he learned in the process and the design of the application. Check out the end result here. Finally, the third article talks about the creation of an application for the iPhone - "an app that would allow other users to add RSS feeds and I could go look for some and add them to my collection". He details the process he went through to create the application and the modules that he used to accomplish it.   Check out the rest of The Bakery for more great CakePHP-related articles and tutorials.
431145
On the "start up web 2.0" blog today, there's a set of benchmarks comparing two popular PHP frameworks - CakePHP and CodeIgniter - and how the fare in the standard "Hello World" sort of test.   After reading How fast is your framework I was rather intrigued to compare CakePHP and CodeIgniter. [...] Each framework is required to have the output "HelloWorld!" produced from a view and a controllers will obviously have to be created.   He ran the tests with the Apache benchmark tool (ab) and the simple code he provides with the results leaning towards CodeIgniter (by a good bit). Overall, it had a faster response time than CakePHP by about half.   Check out his results and grab the code and run it for yourself - see what kind of results you get and how they compare.
350288
Well, according to Soledad Pendaes, PHP will never have a (real) Rails-like framework because of some of the limitations with objects inherent to the language.   I know the title is harsh but it's so true. At least it is according to nowadays php's implementation of classes and objects, which do not permit to "reopen" and add or redefine new methods to an existing class definition, which is the basis upon Rails (and I presume lots more of applications and frameworks) is built.   The post goes on to talk about they "why" behind the statement - basically that this kind of functionality makes it easier to "Extend. Morph. Adapt. Improve. Refine." your applications. He talks some about other frameworks that have tried to offer the same kinds of functionality Rails does (CakePHP and Symfony) but notes that they still have their limitations (in specific, mentioning CakePHP's AppModel functionality).
770095
Felix Geisendorfer has a quick tip for CakePHPers out there today - an update to the framework that might cause a "gotcha" moment in your code:   Just got bitten by this one when updating to the latest version of CakePHP. If you use code [checking to see if the return from a save() is true] in your app, you're in for a surprise. Because as of revision 5895 Model::save() now returns Model::data on success if its not empty.   He notes that most developers don't seem to do it this way, but it tripped him up enough to where he wanted to share it with the CakePHP community so they'd know. Check out the comments on the post for other issues that might be caused by the change.
611971
Although frankly I really didn't feel the need to read the entire thread, I can tell you that the posting to the PHP 3 mailing list is related to the Smarty Templating Engine back in the day. In fact, I believe this was the original spec Andrei proposed before Smarty even existed. Although I don't remember the exact e-mail, this posting reminded me that there was a point in time I thought exactly this way... quoting myself:
84402
The Bakery has five new items they've recently posted - a few new articles, helper information and tutorials. Here's the list:   CSV Helper - I was recently outputting some comma-delimited data and thought I would benefit from a simple csv helper p28n, the top to bottom persistent internationalization tutorial - For some developers, allowing a website to support multiple languages is essential. Luckily cakePHP 1.2 has the foundations available to make this possible. Tracking navigation history of a user - Many times it can be very useful to track the navigation history of a user. [...] With this HistoryComponent, it's extremely easy to handle such actions. Habtm hacks to menage columns in both models - I had a habtm relationship between two models and when i did a "findall" in a model i couldn't filter the rows with a clause from the the other model. SecureGet Component - I am not pretending this can replace ACL or more complex implementation, it's just a small component, inspired a bit from the Security component.   If you're a CakePHP developer, you'd do well to check out The Bakery for these and more great Cake-related articles, tutorials and information.