Run server locally:
bin/cake migrations migrate
bin/cake migrations rollback
bin/cake bake migration CreateProducts name:string description:text created modified
- The primary key column named
idwill be added implicitly.
- default column type will be
stringif not mentioned
modifiedwill be created as
Add Column to an existing table:
bin/cake bake migration AddPriceToProducts price:decimal
Add Column and Index to an existing table:
bin/cake bake migration AddNameIndexToProducts name:string:index
And for more on migrations, check this page
Create Model, Views, Controllers (equivalent to scaffolding in Rails)
- Create the migration
- Run the migrations
- Run bake all command for the resource. For products that would be:
bin/cake bake all products
Model validations are done in:
Model associations are done in: (same file as above)
Is there a console similar to
bin/rails c ?
Yes there is one
To find a list of all projects:
Creating namespaced controllers
for creating routes like
To bake everything:
bin/cake bake all Users --prefix=admin
bin/cake bake controller Users --prefix Admin
bin/cake bake template Users --prefix Admin
How to do User password hashing?
Open the user entity file
Add this method:
Now user password will be hashed whenever a user is created or updated.
How to add Authentication component and allow user to login and logout.
Add the below inside
CakePHP standard is to use an
password for loging in. If
username, the code will look as below:
Next we need to setup a login and logout method:
and paste the login and logout methods
create Login Form at:
How to show user logged in / logged out info in navbar
Add this in
How to print to log files?
In the controller
tail log files from the application root path:
tail -f logs/error.log logs/debug.log