wheels scaffold
Generate complete CRUD scaffolding for a resource.
Synopsis
Description
The wheels scaffold
command generates a complete CRUD (Create, Read, Update, Delete) implementation including model, controller, views, tests, and database migration. It's the fastest way to create a fully functional resource.
Arguments
name
Resource name (singular)
Required
Options
properties
Model properties (format: name:type,name2:type2)
belongs-to
Parent model relationships (comma-separated)
has-many
Child model relationships (comma-separated)
--api
Generate API-only scaffold (no views)
false
--tests
Generate test files
true
--migrate
Run migrations after scaffolding
false
--force
Overwrite existing files
false
Examples
Basic scaffold
Scaffold with properties
Scaffold with associations
API scaffold
Scaffold with auto-migration
What Gets Generated
Standard Scaffold
Model (
/models/Product.cfc
)Properties and validations
Associations
Business logic
Controller (
/controllers/Products.cfc
)All CRUD actions
Flash messages
Error handling
Views (
/views/products/
)index.cfm
- List all recordsshow.cfm
- Display single recordnew.cfm
- New record formedit.cfm
- Edit record form_form.cfm
- Shared form partial
Migration (
/db/migrate/[timestamp]_create_products.cfc
)Create table
Add indexes
Define columns
Tests (if enabled)
Model tests
Controller tests
Integration tests
API Scaffold
Model - Same as standard
API Controller - JSON responses only
Migration - Same as standard
API Tests - JSON response tests
No Views - API doesn't need views
Generated Files Example
For wheels scaffold name=product properties=name:string,price:decimal,stock:integer
:
Model: /models/Product.cfc
/models/Product.cfc
Controller: /controllers/Products.cfc
/controllers/Products.cfc
View: /views/products/index.cfm
/views/products/index.cfm
Form Partial: /views/products/_form.cfm
/views/products/_form.cfm
Migration: /db/migrate/[timestamp]_create_products.cfc
/db/migrate/[timestamp]_create_products.cfc
Routes Configuration
Add to /config/routes.cfm
:
This creates all RESTful routes:
GET /products - index
GET /products/new - new
POST /products - create
GET /products/[key] - show
GET /products/[key]/edit - edit
PUT/PATCH /products/[key] - update
DELETE /products/[key] - delete
Post-Scaffold Steps
Run migration (if not using
--migrate
):Add routes to
/config/routes.cfm
:Restart application:
Test the scaffold:
Visit
/products
to see the indexCreate, edit, and delete records
Run generated tests
Customization
Adding Search
In controller's index()
:
Adding Pagination
Adding Filters
Template Customization
The scaffold command uses templates to generate code. You can customize these templates to match your project's coding standards and markup preferences.
Template Override System
The CLI uses a template override system that allows you to customize the generated code:
CLI Templates - Default templates are located in the CLI module at
/cli/templates/
App Templates - Custom templates in your application at
/app/snippets/
override the CLI templates
This means you can modify the generated code structure by creating your own templates in the /app/snippets/
directory.
How It Works
When generating code, the CLI looks for templates in this order:
First checks
/app/snippets/[template-name]
Falls back to
/cli/templates/[template-name]
if not found in app
Customizing Templates
To customize scaffold output:
Copy the template you want to customize from
/cli/templates/
to/app/snippets/
Modify the template to match your project's needs
Run scaffold - it will use your custom template
Example for customizing the form template:
Available Templates
Templates used by scaffold command:
crud/index.txt
- Index/list viewcrud/show.txt
- Show single record viewcrud/new.txt
- New record form viewcrud/edit.txt
- Edit record form viewcrud/_form.txt
- Form partial shared by new/editModelContent.txt
- Model file structureControllerContent.txt
- Controller file structure
Template Placeholders
Templates use placeholders that get replaced during generation:
|ObjectNameSingular|
- Lowercase singular name (e.g., "product")|ObjectNamePlural|
- Lowercase plural name (e.g., "products")|ObjectNameSingularC|
- Capitalized singular name (e.g., "Product")|ObjectNamePluralC|
- Capitalized plural name (e.g., "Products")|FormFields|
- Generated form fields based on properties<!--- CLI-Appends-Here --->
- Marker for future CLI additions
Best Practices
Properties: Define all needed properties upfront
Associations: Include relationships in initial scaffold
Validation: Add custom validations after generation
Testing: Always generate and run tests
Routes: Use RESTful resources when possible
Security: Add authentication/authorization
Templates: Customize templates in
/app/snippets/
to match your project standards
Comparison with Individual Generators
Scaffold generates everything at once:
See Also
wheels generate model - Generate models
wheels generate controller - Generate controllers
wheels generate resource - Generate REST resources
wheels dbmigrate latest - Run migrations
Last updated
Was this helpful?