Scaffolding is a great way of getting the early parts of developing a web application started. Early database schemas are volatile and subject to change, which is perfectly normal in the early part of the design process. This has a downside: a web developer hates creating forms that never will see real use. To reduce the strain on the developer, scaffolding has been included in Cake. Scaffolding analyzes your database tables and creates standard lists with add, delete and edit buttons, standard forms for editing and standard views for inspecting a single item in the database. To add scaffolding for your application, in the controller, add the $scaffold
variable:
class CategoriesController extends AppController { var $scaffold; }
One important thing to note about scaffold: it expects that any field name that ends with _id
is a foreign key to a table which has a name that precedes the underscore. So, for example, if you have nested categories, you'd probably have a column called parent_id
. With this release, it would be best to call this parentid. Also, when you have a foreign key in your table (e.g. titles table has category_id
), and you have associated your models appropriately (see Understanding Associations, 6.2), a select box will be automatically populated with the rows from the foreign table (category) in the show/edit/new views. To set which field in the foreign table is shown, set the $displayField
variable in the foreign model. To continue our example of a category having a title:
class Title extends AppModel { var $displayField = 'title'; }