Archive for the 'Misc' Category

Upgrading to Cake 1.2

Upgrading to 1.2.4.8284 stable from the 1.2.0.6311 beta.

Recently, CakePHP.org released their 1.2 ’stable’ build (specifically, 1.2.4.8424), and appear to have moved on to working on version 1.3.  Since it’s still a couple of weeks till my school starts up again, it seemed like a good time to move my StudentTracker web app forwards to the current stable version.  In this blog post, I’m going to briefly comment on a couple of issues I ran into, in the hopes of helping out other people who are upgrading to Cake 1.2.

Given that I’m upgrading from an earlier, beta version of 1.2 to the stable, final version of 1.2 [1], one would expect the upgrade to be quick and pretty painless; the process largely was.   http://book.cakephp.org/view/411/Migrating-from-CakePHP-1-1-to-1-2 provides an nice ‘checklist’ of common issues to check for, and was incredibly helpful.

That said, there was really only two things that gave me trouble:

  1. Use App::import instead of vendor()
    In the earlier version of CakePHP, if you wanted to include PHP files from the ‘app/vendors’ directory, you used the vendor() function.  This was all well and dandy, and worked great.  While I can’t find it right now, I swear that there was a page of Cake documentation that clearly stated the intention that the app/vendors/ directory would not have any particular naming convention imposed on it.  This is exactly what one would expect for a directory that’s intended to hold third party, general-purpose PHP libraries (i.e., libraries that have no knowledge of CakePHP).  Looking at the code for the vendor() function itself in Cake 1.1, one can see that it (basically) checked that the specified file existed in the vendors subdirectory, and then included it (using require_once).  vendor() did not inflect the name of the library.
    vendor() is replaced by the new App::import function.  App::import does inflect the library name.  This means that if you try to replace, say:

    vendor('StudentTracker/ResultSet');

    with:

    App::import( 'Vendor', 'StudentTracker/ResultSet');

    You’ll get an error as Cake attempts to inflect the ‘StudentTracker/ResultSet’ string, and ends up with something like ‘app/student_tracker/result_set.php’, which of course doesn’t exist.

    Instead, what you need to do is specify the path to the file yourself, like so:

    App::import( 'Vendor', 'StudentTracker/ResultSet',
            array('file' => 'StudentTracker'.DS.'ResultSet.php'));

    I find this awkward, and I think that it violates the spirit of the vendors directory. But I didn’t get an affirmative response to my Google Group posting about this, so I guess the inflection is intentional.

  2. Model::execute is kind of deprecated – use Model::query instead
    Model::execute has now been replaced with Model::query.  This seems like a reasonable change, and once I knew that the change needed to be made, it was a quick and painless switch.  The only problem was that the deprecation is semi-documented, in the Google Group (specifically here: http://groups.google.com/group/cake-php/browse_thread/thread/8c0edd5f43dad22d/73ec7bf768500bf9?lnk=gst&q=execute#73ec7bf768500bf9). 
    What tripped me up is the fact that Model::execute still exists in the CakePHP 1.2.4.8284 code base.  Since my code used this method, and because the method still exists, I didn’t get a ‘method not found’ error, which would have been a clear indication that it had been deprecated and removed.  It’s deprecation is also not listed in the upgrade guide, so it’s easy to miss. 

There were (as always) a number of minor, dumb mistakes of my own that I needed to iron out (including my use of echo $this->render(); – I keep asking myself how this ever worked correctly :)   )(FWIW, that lined caused the view to be displayed twice in the same page).

Overall, the experience was quick, painless, and extremely fast.  Admittedly, I’m only upgrading from the beta (and not from version 1.1), but I’m guessing that the 1.1 upgrade should be quick and easy, too.


 [1] At least, I *think* it’s the final version – 1.2.4.8284 is marked as being ’stable’ on the CakePHP website, and it appears that the next dev version is labeled 1.3

August 19 2009 | Misc | No Comments »

Hello, World!

My name is Mike Panitz, and I’ve been teaching computer programming (and occassionally math) at Cascadia Community College since 2001.  I put this blog together mostly for fun, but also as a platform to talk about (computer) technology, teaching, and how to apply one to the other.

My homepage is at http://faculty.cascadia.edu/mpanitz/

June 20 2009 | Misc | No Comments »