Code Generation with Bake

The cake console is run using the PHP CLI (command line interface).If you have problems running the script, ensure that:

  • You have the PHP CLI installed and that it has the proper modules enabled (eg: MySQL, intl).
  • Users also might have issues if the database host is ‘localhost’ and should try ‘127.0.0.1’ instead, as localhost can cause issues with PHP CLI.
  • Depending on how your computer is configured, you may have to set execute rights on the cake bash script to call it using bin/cake bake.
    Before running bake you should make sure you have at least one databaseconnection configured. See the section on database configuration for more information.

When run with no arguments bin/cake bake will output a list of availabletasks.

For windows system try with bin\cake bake.

You should see something like:

  1. $ bin/cake bake
  2.  
  3. Welcome to CakePHP v3.4.6 Console
  4. ---------------------------------------------------------------
  5. App : src
  6. Path: /var/www/cakephp.dev/src/
  7. PHP : 5.6.20
  8. ---------------------------------------------------------------
  9. The following commands can be used to generate skeleton code for your application.
  10.  
  11. Available bake commands:
  12.  
  13. - all
  14. - behavior
  15. - cell
  16. - component
  17. - controller
  18. - fixture
  19. - form
  20. - helper
  21. - mailer
  22. - migration
  23. - migration_diff
  24. - migration_snapshot
  25. - model
  26. - plugin
  27. - seed
  28. - shell
  29. - shell_helper
  30. - task
  31. - template
  32. - test
  33.  
  34. By using `cake bake [name]` you can invoke a specific bake task.

You can get more information on what each task does, and what options areavailable using the —help option:

  1. $ bin/cake bake --help
  2.  
  3. Welcome to CakePHP v3.4.6 Console
  4. ---------------------------------------------------------------
  5. App : src
  6. Path: /var/www/cakephp.dev/src/
  7. PHP : 5.6.20
  8. ---------------------------------------------------------------
  9. The Bake script generates controllers, models and template files for
  10. your application. If run with no command line arguments, Bake guides the
  11. user through the class creation process. You can customize the
  12. generation process by telling Bake where different parts of your
  13. application are using command line arguments.
  14.  
  15. Usage:
  16. cake bake.bake [subcommand] [options]
  17.  
  18. Subcommands:
  19.  
  20. all Bake a complete MVC skeleton.
  21. behavior Bake a behavior class file.
  22. cell Bake a cell class file.
  23. component Bake a component class file.
  24. controller Bake a controller skeleton.
  25. fixture Generate fixtures for use with the test suite. You
  26. can use `bake fixture all` to bake all fixtures.
  27. form Bake a form class file.
  28. helper Bake a helper class file.
  29. mailer Bake a mailer class file.
  30. migration Bake migration class.
  31. migration_diff Bake migration class.
  32. migration_snapshot Bake migration snapshot class.
  33. model Bake table and entity classes.
  34. plugin Create the directory structure, AppController class
  35. and testing setup for a new plugin. Can create
  36. plugins in any of your bootstrapped plugin paths.
  37. seed Bake seed class.
  38. shell Bake a shell class file.
  39. shell_helper Bake a shell_helper class file.
  40. task Bake a task class file.
  41. template Bake views for a controller, using built-in or
  42. custom templates.
  43. test Bake test case skeletons for classes.
  44.  
  45. To see help on a subcommand use `cake bake.bake [subcommand] --help`
  46.  
  47. Options:
  48.  
  49. --connection, -c Database connection to use in conjunction with `bake
  50. all`. (default: default)
  51. --everything Bake a complete MVC skeleton, using all the available
  52. tables. Usage: "bake all --everything"
  53. --force, -f Force overwriting existing files without prompting.
  54. --help, -h Display this help.
  55. --plugin, -p Plugin to bake into.
  56. --prefix Prefix to bake controllers and templates into.
  57. --quiet, -q Enable quiet output.
  58. --tablePrefix Table prefix to be used in models.
  59. --theme, -t The theme to use when baking code. (choices:
  60. Bake|Migrations)
  61. --verbose, -v Enable verbose output.

Bake Themes

The theme option is common to all bake commands, and allows changing the baketemplate files used when baking. To create your own templates, see thebake theme creation documentation.