Show Menu
Cheatography

CakePHP 3 Bake Cheat Sheet (DRAFT) by

CakePHP 3 bake cheetsheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

CakePHP Console Cheat Sheet

Details extracted from CakePHP 3.2.x command prompt.

Instal­lation

composer require --dev cakeph­p/b­ake­:~1.0
PhpStorm comes with composer built in.
To install CakePHP via PhpStorm, use the FileNewComposer Project.
Then filter for CakePHP and select the
cakeph­p\app
composer project.

CakePHP Console

Run the CakePHP console from project root
bin/cake
(use
bin\cake
for Windows)
Possible "­she­lls­"
bake
,
migrations
,
i18n
,
orm_cache
,
plugin
,
routes
,
server
,
behavi­or_time
,
console
,
orm
Run Cake Server (usually on localhost port 8765)
bin/cake server
Run migrations shell (with help)
bin/cake migrations -h
Run bake with plugin prefix
bin/cake bake.bake -h
PHP CLI must be installed and in the path.

Bake Shell Common Options

help
--help
or
-h
Verbose output
--verbose
or
-v
Quiet output
--quiet
or
-q
Plugin to bake into
--plugin
or
-p
Force overwrite of existing files
--force
or
-f
Datasource connection to get data from (default: default)
--conn­ection
or
-c
Theme to use when baking
--theme
or
-t
Do not bake a test skeleton
--no-test
Do not bake generic CRUD action methods
--no-a­ctions
These options are common to most of the cake shell commands.

Server Shell

Run server shell with (defaults)
bin/cake server
Run server shell and get help
bin/cake server --help
Run server shell on port 9999
bin/cake server --port 9999
Run server shell using IP of 10.0.0.2
bin/cake server --host 10.0.0.2
Run server shell with document root dummy/­app­/root
bin/cake server --docu­men­t_root dummy/­app­/root
Run server shell with verbose output
bin/cake server --verbose
example
bin/cake -H 10.0.0.2 -p 9999 -d dummy/­app­/root -v

Bake Shell: Model

Run bake model shell and list all tables
bin/cake bake model
Bake model class for Friends table
bin/cake bake model Friends
Run bake model shell and get help
bin/cake bake model --help
Genera­lised use:
bin/cake bake model  [subcommand] [options] [<Mo­del­Nam­e>] 
Options
other than the default ones
Table name if "­non­-co­nve­nti­ona­l" table naming used
--table <Ta­ble­Nam­e>
Disable generation of Entity class
--no-e­ntity
Disable generation of Table class
--no-table
Disable generation of validation rules
--no-v­ali­dation
Disable generation of a rules checker
--no-rules
Disable generatin of associ­ations
--no-a­sso­cia­tions
Disable generation of fields
--no-f­ields
Comma separated list of fields to make accessible
--fields <fi­eld­nam­e>[,<f­iel­dna­me>...] 
Comma separated list of hidden fields
--hidden <fi­eld­nam­e>[,<f­iel­dna­me>...] 
Set the primary key field or fields (comma separated)
--prim­ary-key <ke­y-f­iel­d>[,<k­ey-­fie­ld>...] 
Display field if you would like to select one
--disp­lay­-field <fi­eld­-na­me>
 

Cake Routes Shell

List of all Routes
bin/cake routes
URL Parsing Testing
bin/cake routes check route-­and­-op­tions
example
bin/bake routes check /bookm­ark­s/e­dit/1
URL Generation Testing
bin/cake routes generate contro­ller:contro­lle­rname action:action other options
example
bin/cake routes generate contro­lle­r:B­ook­marks action­:edit 1
example with string parameters
bin/cake routes check "­/bo­okm­ark­s/?­pag­e=1­&s­ort­=ti­tle­&d­ire­cti­on=­des­c"

Bake Shell: Controller

Bake a controller skeleton
cake bake controller [subcommand] [options] [<na­me>]
Bake the My controller with CRUD actions
bin/cake bake controller MyCont­roller
Bake all contro­llers with CRUD methods
Beware: This may overwrite existing contro­llers
cake bake controller all
Options
Plugin to bake into
--plugin
or
-p
Force overwrite of existing files
--force
or
-f
Datasource connection to get data from (default: default)
--conn­ection
or
-c
Theme to use when baking
--theme
or
-t
Components to use (comma separated)
--comp­onents
Helpers to use (comma separated)
--helpers
Namesp­ace­/ro­uting prefix to use
--prefix
Do not bake a test skeleton
--no-test
Do not bake generic CRUD action methods
--no-a­ctions
<na­me> is the name of the controller to bake, and you may use Plugin.name to bake contro­llers into plugins (optio­nal).

Version Control

Version
Date
Notes
1.0
25 April 2016
Initial version, there are many more commands to add
This will be updated each time we add new content to the cheat sheet.