使用 Bake 生成代码

Bake 控制台使用 PHP CLI(命令行界面)运行。如果您在运行脚本时遇到问题,请确保

  1. 您已安装 PHP CLI 并且已启用正确的模块(例如:MySQL、intl)。

  2. 如果数据库主机是 ‘localhost’,用户也可能会遇到问题,应该尝试使用 ‘127.0.0.1’ 来代替,因为 localhost 会导致 PHP CLI 出现问题。

  3. 根据您计算机的配置方式,您可能需要设置 cake bash 脚本的执行权限,以便使用 bin/cake bake 调用它。

在运行 bake 之前,您应该确保至少配置了一个数据库连接。

您可以通过运行 bin/cake bake --help 来获取可用的 bake 命令列表(对于 Windows 用户,使用 bin\cake bake --help

$ bin/cake bake --help
Current Paths:

* app:  src/
* root: /path/to/your/app/
* core: /path/to/your/app/vendor/cakephp/cakephp/

Available Commands:

Bake:
- bake all
- bake behavior
- bake cell
- bake command
- bake command_helper
- bake component
- bake controller
- bake controller all
- bake enum
- bake fixture
- bake fixture all
- bake form
- bake helper
- bake mailer
- bake middleware
- bake model
- bake model all
- bake plugin
- bake template
- bake template all
- bake test

To run a command, type `cake command_name [args|options]`
To get help on a specific command, type `cake command_name --help`

Bake 主题

主题选项在所有 bake 命令中很常见,它允许在烘焙时更改使用的 bake 模板文件。要创建自己的模板,请参阅 bake 主题创建文档.