Well the redesign and rebuild is complete. I’ve gutted my site and rebuilt it from the ground up. There are more changes than just a shiny new design though. With this redesign I’m shifting the focus of the site around a bit as well.
CakePHP 1.2 is a fantastic improvement over 1.1. However like many, my work has a stable release only policy. So I’m stuck using 1.1 at work for the time being. But after drinking the 1.2 juice, 1.1 is missing some of the potent automagic flavours. First up editing multiple rows in models. The stock syntax is lacking in that it doesn’t support this at all.
Super fresh in the SVN builds of CakePHP 1.2 is the new code coverage analysis. If you are living on the bleeding edge of cake development or just want a preview of the neat things to come once 1.2 is complete read on.
The guys at debuggable have contributed a fantastic tool to the testing suite for CakePHP 1.2.
Indicating to the user which fields are required is something that increases usuability, helping the user fill out the form more effectively and efficiently. These visual cues have absolutely nothing to do with the structure of the document, and would best be handled by CSS.
I was recently asked to join the development team at CakePHP a position I graciously and excitedly accepted. And although I’m still a bit wet behind the ears, I thought I would share some of my experiences in how you can get involved with Open Source Software.
Earlier this week I learned that isset() behaves a little differently than I had expected when dealing with arrays. Now I already knew that isset() would return false on a variable not existing, or being set to null. However, I was not expecting it to return false on an array key existing and being set to null.
Well today I took the time to upgrade to CakePHP 1.2 RC1 in the spirit of ‘eating your own dogfood’. I got the usual warnings about vendor() being deprecated. I also took the time to switch over all my Bindable calls to the fresh core Containable Behavior. Which for the most part consisted of changing restrict() calls to contain() calls.
Well I just got back from a wonderful 2 week vacation of europe. My wife and I went to Amsterdam, Rome and Paris, for an art-geekout. We went to every museum we could and saw tons of beautiful works that really need to be seen in the stone and paint. We took tons of photos and I hopefully will find the time to do some painting based on them in the upcoming months.
Often on IRC and the CakePHP google group, I hear people asking how to get values out of the Session or how to find out what is currently in the Session. Generally this is connected to AuthComponent, which is can be complicated component. However, some simple ‘crude’ PHP tactics can make the “whats’s in my session?” question very simple.
When bakers first start using CakePHP there is a tendency to use requestAction() more often than it should be. Often requestAction() gets used to pull in common elements like recent posts or new comments, or to make menus. This makes sense in a way as it keeps the comments code in the CommentsController and all is well.
Routing in CakePHP is quite flexible in how you can route your urls to your controllers and actions. Offering both variable replacement and regex routing. You can route almost any parameter that is set by dispatcher and more. So lets try a few of these.
With all the talk of testing going on, I thought it would be good to look at how tests work and what is makes them tick. SimpleTest handles the bulk of test case execution, however, there are a few CakePHP specifics that are not part of a normal SimpleTest::UnitTestCase.
The documentation for CakePHP has grown in leaps and bounds since the creation of the cookbook. Today I wanted to look at a few methods and conventions that may not be crystal clear from reading the book or api.
Object is the parent class for almost all other classes in CakePHP.
In my previous Auth and Acl tutorial I mentioned that I wasn’t including a way for users ARO to be automatically updated when a User’s group was updated. Well ‘hepper’ posted a patch to the AclBehavior in the comments to that article.
As I post more and more code here, I’m finding it tedious to update all the various .zip files of code as I make changes. So I’ve taken a page from Tim and Felix and made an account at gitHub. This makes it easy for me and you to find the newest revision of whatever you may be looking for.
Making RSS feeds and alternative content types other than HTML opens a lot of options in how your content can be used, displayed and combined. In prior version of cakePHP webservices were indicated by prefixing a url with the desired content type so an xml version of a blog index might look like xml/posts/index.
I like many webdevelopers build a lot of forms. Forms are the bread and butter of web applications, and while making forms is getting easier for developers, users often still have a hard time with them. In these circumstances it is necessary to give them a help above and beyond ‘password’.
If you are following the development of CakePHP today is a good day for you. RC3 was released today! We have all been working really hard to make this Release Candidate better than the last one. There have been over 400 commits since the last RC2. Some of the big changes are related to performance. Larry Masters and the rest of the team have been hard at work making CakePHP snappier and all around speedier.
Eclipse is widely popular, robust and powerful IDE. It supports PHP through the PDT project . PDT gives you some good PHP related development tools, including code completion & code templates to help you save some time.
As webservices grow so does the need for being able to communicate with them in an easy fashion. This simple blog alone uses 2 webservices. The recent tracks at the bottom is a feed I pull from Last.fm and my spam protection is provided by Akismet. When first building my site I looked for an already built solution and found a partial solution in Felix GeisendÃ¶rfer’s WebModel.
So 1.2 is nearly complete, the code is frozen and there are only a few bugs left to squash before the final release is ready. So you want to upgrade your application from 1.1 to 1.2. Although the 1.2 moniker suggests a ‘minor’ version, a lot has changed under the hood and entire API’s have been rebuilt.
At some point or another we’ve all had to make a data model that involved various flags to indicate different statuses / modes for an object. Often the schema for such a data model may end up looking like
I’ve had quite the busy last little month or two. My wife and I have been house shopping for a while, and found a place about 2 months ago. However, just last weekend we moved into our new (to us at least) condo in west Toronto.
The new sideproject is the CakePHP DebugKit . I’ve been hard at work building a ‘debug toolbar’ for CakePHP.
I’ve been working hard over the last few weeks to improve the DebugKit and have added what I think are some pretty cool features. First up is FireCake. FireCake is a fully functional FirePHP library built specifically with CakePHP in mind.
I’ve recently been doing some work on some CLI tools, and I came across the need to “paginate” a long list of file. Instead of dumping out 40+ items to the screen all at once, which would be confusing and hard to read, I wanted a more elegant way of showing only a section on the huge list at once.
I recently wrote an article about testing CakePHP controllers the hard way where I covered testing controllers by running their methods manually. I hinted at some additional tricks that could be performed by using Mock Objects. Today I’m going to spill the beans on Mocks, and how I use them when testing my Controllers.
So I’ve been working away on DebugKit the last few weeks. And I think its at a level where I can suggest other people give it a whirl. Its not at a stable release point. But if you are feeling adventurous and don’t mind using beta code give it a try. There are a few notable features have been added, so in no particular order here they are.
Generating code coverage for test cases is a handy feature, it gives you a quick and easy way to determine how much of your code is running during your tests. It doesn’t ensure that the tests are good or that you have enough assertions, but code that doesn’t run definitely has not been tested. Before code coverage was created it was very difficult to determine how much code was being run.
Today marks the 1.1 release of DebugKit. After using it for the past few weeks and not finding any new issues or getting and new tickets. A few new features snuck into the release, courtesy of Andy Dawson.
When PHP got a real object oriented system in 5.0, it also got a neat feature taken from Java land. Reflection allows you to introspect & reverse engineer functions, classes, and extensions. In addition you can use reflection to extraction of documentation from classes and functions. In PHP Reflection is done using a number of Reflection classes.
Re-factoring code is a part of any programmers life or should be. Very few people write beautifully clean and well factored code from the start, and I am certainly not one of them. Most times my code starts out a sprawling tangle that takes an additional pass or two to look like something I would consider clean. I find that when programming and designing I start with a rough idea or sketch of what I want to accomplish.
In the ongoing struggle against code bloat and creative ways to do things, I’ve been playing with throwing exceptions from model methods. While not earth shattering stuff, I’ve found it to have a few advantages over returning false. First, you can end up with less if and else statements.
I spend a lot of time in various IRC channels answering questions and helping out, and one recurring theme that pops up again and again is people not knowing what to do when things go wrong. Whether it be a simple error or a logical mixup, people often lack the tools or processes to figure things out. So I thought I would share how I approach errors and problems.
As a mac user, I’m a huge fan of the great work the people at MacPorts do. If you haven’t used MacPorts before, its basically a mac version of apt-get or rpm and allows you to install all kinds of unix-y goodness from source code on OSX.
With the help of Oscar Carlsson I’ve updated the AcoSync Shell and renamed it to the AclExtrasShell. With Oscar’s help we’ve added quick and easy ways to recover and verify your tree structures. AclExtras Shell also incorporates all the existing functionality of AcoSync Shell.
By now you’ve got an awesome Acl and Auth controlled app running. However, making navigation menus is a pain with dynamic, and variable permissions. Outside of making menu elements for each type of Aro and including them in your layout, there currently aren’t many options (at least none that I’m aware of). I was faced with this exact problem a while back, and couldn’t find a suitable solution, so I made one.
GeSHi or the Generic Syntax Highlighter is a simple yet powerful syntax highlighter for many languages. Implemented in many CMS. When I wanted syntax highlighting for my postings I decided to implement GeSHi. I wanted to share my implementation of GeSHi as a CakePHP helper.
So originally when I built this site, I was in the “requestAction is bad” camp. So much so that I created a convoluted Component to assist in the creation of the sideboxes featured on this site. A sample of that code is as follows:
If you’ve been following the ongoing development of the 1.3 branch over at code.cakephp.org:http://code.cakephp.org. You may have noticed that bake has had a significant overhaul, and a number of features and enhancements have been built in.
Previously, I wrote about using two versions of PHP with macports . In it I covered installing PHP4 and PHP5. Since then PHP5.3 has been released as a stable release. However, I needed to maintain my PHP5.2 installation as I have a number of client projects that are on servers using PHP5.2. So to reduce version insanity I wanted to keep 5.2.
Shells are one of the more difficult objects to properly unit test. Since they normally run in a CLI context instead of a web context they provide some interesting challenges. The biggest hurdles are separating the Shell from the CLI environment, and simulating the correct arguments and parameters.
Although PHP5.3 is still hot off the press, and a very exciting release in its own right. I must say I’m far more excited about the grafts and traits that have been proposed for PHP6. While PHP6 is still a fair ways off from being released, Stefan Marr has backported the changes to PHP5.
vCards are a nice added touch for an application that acts as a Address book, or contact management. vCards are easily used by most mail clients, and are a plain text standard making them nice and easy to implement. While hCard and other microformats are gaining popularity, the widespread support still doesn’t exist. Leaving vCard as the primary format to transfer contact information out of a web application
In the last article we created the basic models, controllers and views for our Auth and Acl controlled app as well as initialized the Acl tables. We also bound our groups and users to the Acl through the use of the AclBehavior.
Now, there are many tutorials out there for Auth and ACL in CakePHP. However, none of them (as far as I know of) cover putting together Auth and ACL from beginning to end. That is what I’m going to do in this article. I am splitting the article into two parts; the first about setting up our app and getting the Aros running, the second on building Acos and putting it all together.
Websites need maintenance, and sometimes that maintenance requires the site to go down for a little bit as you tweak the database, add additional capacity or make large changes to the application code. In these circumstances you cannot afford to have users mucking about on your application. However, you might need access to ensure all your amazing upgrades go smoothly or perhaps do the upgrading inside the application itself.
Last night I updated this site to run on the latest 1.3 build. While I know I should have done it earlier, I simply haven’t had the time. And since I went through it, I figured I could document it and share what the upgrade process is like for a small site, that doesn’t see a ton of maintenance action like this one.
I recently read “Clean Code” by Robert Martin an excellent book on writing clear, easy to maintain and well factored code. In it Robert Martin raises the point that methods should do what their names say, shouldn’t have ‘flag arguments’, and should do only one thing. This implies that overloaded methods are out.
New for CakePHP 1.3 is the ability to create and use custom route classes for your application’s routing. In the past the router did double duty, managing route collections and routes were just arrays. In 1.3 Router underwent some surgery and CakeRoute was extracted as an object to represent a single route. While Router was left as a manager of routes.
By now you already know or should know about CakeTestCase::testAction() and the wondrous things it can do. However, testAction has a few shortcomings. It can’t handle redirects, it doesn’t let you use the power of Mocks, and its impossible to make assertions on object state changes. Sometimes you need to do things the hard way, stick your fingers in the mud and work it out.
Over the long Ontario weekend, I took some time to update Acl Extras. It now works with plugins and the improvements made to the Auth + Acl for 1.3. The master branch contains the CakePHP 1.3 compatible version. While the 1.0.0 tag, and 1.0 branch are still compatible with CakePHP 1.2.
I’ve been doing many of the CakePHP releases, since “the great framework apocalypse of imminent doom”. Between then and now, CakePHP has had quite a few releases. During these past few months, I’ve really begun to understand the value of a simple release process. When I initially started doing releases for CakePHP, our release process involved many steps and I was doing them all manually.
I’ve just released another plugin for CakePHP. This one helps reduce the number of HTTP requests made by helping you concatenate and compress your asset files. I’ve been working on it on and off for about 3 months now, and am pretty happy with where it is. It includes both server side and client side libraries for loading compressed files.
Errors and error reporting an important part of the development and debugging cycle. In interpreted languages, there are a number of runtime errors that can really help you debug your code. Some languages like python don’t give you a way to make the errors go away, but for better or worse PHP does.
In the past I’ve used a variety of tools to deploy client sites, most often using version control. However, for my blog I’ve always used FTP. Its a pretty old-school approach, and something that I’ve been lacking the time to correct. Last weekend I finally took the plunge and figured out how to get Capistrano to deploy my site.
In the recent bakery article concerning the ongoing development of CakePHP 2.0. The already underway migration from SimpleTest to PHPUnit was introduced. I wanted to go into some of the reasons and motivations for that decision as well as explain some of the long term benefits.
Since PHP lacks a decimal type, it only has floats and integers. Arbitrary precision floating points are reasonable once you stop expecting them to be precise. I’ve learned to deal with PHP’s floats, and arbitrary precision floats in general. However, floats behaving totally different based on the current locale, was something I didn’t expect.
Work on CakePHP 2.0 is moving along, and I wanted to take some time to discuss and explain one of the sizeable refactorings that has been done for 2.0. In previous versions request parameters were just a bunch of arrays that were copied to the various places they were needed in the framework.
The release of the new API at http://api.cakephp.org wasn’t quite as smooth as I would have liked it. However, since the initial release things have constantly been improving. The search is now much more effective, and global functions are now in the index. So things are looking better each day. I hope to answer a few questions surrounding ApiGenerator today.
Previously I wrote about the changes that have been done for the request handling in CakePHP 2.0. Response handling is another subsystem that has received a significant facelift. As with request information and functionality, response related features were spread across several objects. Controller, RequestHandler and Dispatcher all had a slice of the pie.
Continuing with the trend of CakePHP information here, I’m going to cover some of the acronyms and lexicon of CakePHP. I hang out a lot on #cakephp and there are repeating trends in some of the questions that get asked so hopefully I can answer some of those questions here. As well as provide a bit of my personal experiences.
I recently had a fun idea, that I wanted to try and implement for PHPUnit. I really like coloured console output. PHPUnit already has the option for coloured output, but I wanted more. I wanted to get coloured text for F, E, S, and I that showed up in the test run progress.
In the release announcement for 1.3.7, it was tentatively announced that CakePHP would be moving its documentation over to ReST, Git and sphinx. Having documentation in a git repo, and using sphinx to generate documentation has a few nice wins, that would be difficult to achieve with the current book application.
This week I’ve been participating in the SQLServer Jump-in Camp. My focus for the workshops have been building out better support for IIS and SQL Server in CakePHP. As I generally develop on MacOS, I do development for other platforms through virtual machines. This has worked well with linux servers in the past.
Earlier today I saw the announcement that PHP5.4 will have a built-in web server . I mentioned on twitter that I wasn’t too happy about the server being added. In the discussion that followed, I feel like I wasn’t able to properly convey my thoughts through tweets.
In case you were not able to attend CakeFest 2011. I’ve posted my slides up on slideshare. The event was a great success. Thanks to Graham for organizing the event and to all the attendees. Its great to meet the community and put faces and names to irc handles and mailing list email addresses.