Saturday 17 May 2008

CakePHP 1.2 .vs. 1.1 - Changes #2

Another minor difference to CakePHP in v1.2: template file extensions have changed.

In v1.1, page templates had a filename extension thtml. In v1.2 it is ctp.

The IBM Wiki tutorial suggests that you play with the page template app/views/layouts/default.thtml at the end of part 1. Using CakePHP v1.2, this is app/views/layouts/default.ctp.

CakePHP 1.2 .vs. 1.1 - Changes #1

Being relatively new to CakePHP, I have been working through the IBM tutorials. In particular, the Wiki tutorial fits closely to what I want to build for my first CakePHP implementation.

Part 1 of the tutorial was straightforward. This covers the basics of creating a simple set of models, views and controllers. The result is a set of web pages which display data in tables and offer add / edit / delete functionality.

The tutorial is written for v1.1 of the framework. I have opted for v1.2 - so there are some differences.

The first difference is in the scaffolding. CakePHP v1.1 provides a PHP script "bake.php" in the cake/scripts directory. This is an interactive process and you've got to respond to the menus to drive the scaffolding.


$ php ../scripts/bake.php

Baking ...
----------------------------------------------------------
Name: app
Path: ~/dev/workspace/cakephp/app
----------------------------------------------------------
[M]odel
[V]iew
[C]ontroller

What would you like to bake? (M/V/C)
>


CakePHP v1.2 has a command script 'cake' in the cake/console directory. This can be given command-line args so that the scaffolding can be completed quickly with a few simple commands:


$ ../console/cake bake all users


This then builds a model, view and controller for the named table in the database.