Command Line Tools
wheels generate scaffold
wheels generate scaffold
Section titled “wheels generate scaffold”Generate complete CRUD scaffolding for a resource including model, controller, views, tests, and migration.
Synopsis
Section titled “Synopsis”wheels generate scaffold name [options]wheels g scaffold name [options]wheels g resource name [options] # Alias for scaffoldDescription
Section titled “Description”The wheels scaffold command (alias: wheels g resource) 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.
CommandBox Parameter Syntax
Section titled “CommandBox Parameter Syntax”This command supports multiple parameter formats:
- Positional parameters:
wheels generate scaffold Product(resource name) - Named parameters:
name=value(e.g.,name=Product,properties="name:string") - Flag parameters:
--flagequalsflag=true(e.g.,--apiequalsapi=true) - Flag with value:
--flag=value(e.g.,--properties="name:string")
Parameter Mixing Rules:
ALLOWED:
- All positional:
wheels generate scaffold Product - All named:
name=Product properties="name:string" - Positional + flags:
wheels generate scaffold Product --api --migrate
NOT ALLOWED:
- Positional + named:
wheels generate scaffold Product properties="name:string"(causes error)
Recommendation: Use positional for resource name, flags for options: wheels generate scaffold Product --properties="name:string" --api --migrate
Arguments
Section titled “Arguments”| Argument | Description | Default |
|---|---|---|
name | Resource name (singular) | Required |
Options
Section titled “Options”| Option | Description | Example | Default |
|---|---|---|---|
--properties | Model properties (format: name:type,name2:type2) | --properties="name:string,price:decimal" | |
--belongsTo | Parent model relationships (comma-separated) | --belongsTo=User,Category | |
--hasMany | Child model relationships (comma-separated) | --hasMany=orders,comments | |
--api | Generate API-only scaffold (no views) | --api=true or --api | false |
--tests | Generate test files | --tests=false | true |
--migrate | Run migrations after scaffolding | --migrate=true or --migrate | false |
--force | Overwrite existing files | --force=true or --force | false |
Examples
Section titled “Examples”Basic Examples
Section titled “Basic Examples”# Basic scaffoldwheels g scaffold Productwheels g resource Product # Same as scaffold
# With propertieswheels g scaffold Product --properties="name:string,price:decimal,stock:integer"wheels g resource Product --properties="name:string,price:decimal,stock:integer"
# With associationswheels g scaffold Order --properties="total:decimal,status:string" --belongsTo=User --hasMany=orderItems
# API-only scaffold (no views)wheels g scaffold Product --api --properties="name:string,price:decimal"wheels g resource Product --api --properties="name:string,price:decimal"
# With auto-migrationwheels g scaffold Category --properties="name:string" --migrateAdvanced Examples
Section titled “Advanced Examples”# Complete e-commerce productwheels generate scaffold Product --properties="name:string,description:text,price:decimal,inStock:boolean" --belongsTo=Category --hasMany=orderItems,reviews --migrate
# Blog systemwheels generate scaffold Post --properties="title:string,content:text,published:boolean" --belongsTo=User --hasMany=comments --apiParameter Details
Section titled “Parameter Details”Properties Format:
- Format:
--properties="name:type,name2:type2" - Types:
string,text,integer,decimal,boolean,date,datetime,time - Always use quotes around the entire properties string
Associations:
--belongsTo=Model1,Model2(PascalCase parent models)--hasMany=model1,model2(camelCase plural child models)
Resource Name:
- Must be singular (e.g.,
Product, notProducts) - PascalCase recommended (e.g.,
OrderItem,UserProfile)
What Gets Generated
Section titled “What Gets Generated”Standard Scaffold
Section titled “Standard Scaffold”- Model (
/models/Product.cfc) - Properties, validations, associations - Controller (
/controllers/Products.cfc) - All CRUD actions (index, show, new, create, edit, update, delete) - Views (
/views/products/) - index, show, new, edit, _form partial - Migration (
/app/migrator/migrations/[timestamp]_create_products.cfc) - Table creation with indexes - Tests - Model, controller, and integration tests (if
--tests=true)
API Scaffold
Section titled “API Scaffold”- Model - Same as standard
- API Controller - JSON responses only, no views
- Migration - Same as standard
- API Tests - JSON response tests
Generated Code Structure
Section titled “Generated Code Structure”For wheels scaffold Product --properties="name:string,price:decimal":
Model: Properties with validations (presence, uniqueness, numerical) Controller: Full CRUD actions with flash messages and error handling Views: List, show, new/edit forms with proper encoding and form helpers Migration: Table with columns, timestamps, and indexes
Run the command to see the complete generated code.
Routes Configuration
Section titled “Routes Configuration”Add to /config/routes.cfm:
<cfset resources("products")>This creates all RESTful routes (index, new, create, show, edit, update, delete).
Post-Scaffold Steps
Section titled “Post-Scaffold Steps”- Run migration (if not using
--migrate):wheels dbmigrate latest - Add routes to
/config/routes.cfm:<cfset resources("products")> - Reload application:
wheels reload - Test: Visit
/productsand test CRUD operations
Common Customizations
Section titled “Common Customizations”Search:
function index() { products = StructKeyExists(params, "search") ? model("Product").findAll(where="name LIKE :search", params={search: "%#params.search#%"}) : model("Product").findAll();}Pagination:
products = model("Product").findAll(page=params.page ?: 1, perPage=20);Authentication:
function init() { filters(through="authenticate", except="index,show");}Template Customization
Section titled “Template Customization”Customize generated code by overriding templates:
- Copy templates from
/cli/templates/to/app/snippets/ - Modify templates to match your project style
- CLI uses your custom templates automatically
Available Templates:
crud/index.txt,crud/show.txt,crud/new.txt,crud/edit.txt,crud/_form.txtModelContent.txt,ControllerContent.txt
Template Placeholders:
|ObjectNameSingular|,|ObjectNamePlural|- Lowercase names|ObjectNameSingularC|,|ObjectNamePluralC|- Capitalized names|FormFields|- Generated form fields
Troubleshooting
Section titled “Troubleshooting”Common Issues
Section titled “Common Issues”Parameter Syntax Errors
Section titled “Parameter Syntax Errors”❌ Wrong:
wheels generate scaffold Product properties="name:string" # Positional + named (ERROR)wheels generate scaffold Product --properties=name:string # Missing quoteswheels generate scaffold Comment --belongsTo=product # Wrong case (should be Product)✅ Correct:
wheels generate scaffold Product --properties="name:string,price:decimal"wheels generate scaffold Comment --belongsTo=Product --hasMany=repliesRules:
- Always use quotes around properties:
--properties="name:string" - Use PascalCase for belongsTo:
--belongsTo=User - Use camelCase plural for hasMany:
--hasMany=posts,comments - Never mix positional and named parameters
File Generation Issues
Section titled “File Generation Issues”Problem: Files not created or partially generated
Solutions:
- Check directory permissions:
ls -la app/models app/controllers - Use
--forceto overwrite existing files - Use singular PascalCase names (e.g.,
Product, notproductsorproduct-item)
Migration Issues
Section titled “Migration Issues”Problem: Migrations not created or contain errors
Solutions:
- Use valid property types:
string,text,integer,decimal,boolean,date,datetime - Check generated migration:
ls app/migrator/migrations/*create* - Foreign keys are auto-generated for associations
Route Issues
Section titled “Route Issues”Problem: Routes not working
Solution: Add resources to /config/routes.cfm:
<cfscript>mapper() .resources("products") .wildcard().end();</cfscript>Validation Checklist
Section titled “Validation Checklist”Before scaffolding:
- Verify Wheels directory structure exists
- Check for naming conflicts
- Plan properties and associations
After scaffolding:
- Check files were created:
ls app/models/ app/controllers/ app/views/ - Run migrations:
wheels dbmigrate latest - Add routes to
routes.cfm - Test at
/products
Best Practices
Section titled “Best Practices”- Plan First: Define properties, associations, and validations before scaffolding
- Start Simple: Begin with basic properties, add complexity later
- Use Templates: Customize templates in
/app/snippets/to match your project standards - Test Immediately: Run generated tests and visit the scaffold in browser
- Security: Add authentication/authorization filters after generation
- Incremental: Scaffold one resource at a time, test, then move to the next
See Also
Section titled “See Also”- wheels generate model - Generate models only
- wheels generate controller - Generate controllers only
- wheels generate view - Generate views only
- wheels dbmigrate latest - Run migrations