The easiest way to create a new CakePHP project is via Composer (if you don't know about composer look here for more info)
If you need to install it and are on a windows machine follow this guide
If you are on Linux/Unix/OSX follow this guide
Open a console window and navigate to your installation of php (on Windows with the default xampp installation this is C:\xampp\php
)
To create an empty project then run the following command:
php composer.phar create-project --prefer-dist cakephp/app name_of_your_project
The magic of CakePHP is baking - an automated generation of controller, model and view code with basic CRUD options.
Before baking you need to have your database connection configured. To do this you need to edit the file config/app.php
in your project.
'Datasources' => [
'default' => [
'className' => 'Cake\Database\Connection',
'driver' => 'Cake\Database\Driver\Mysql',
'persistent' => false,
'host' => 'localhost',
'username' => 'my_app', //in basic xampp: root
'password' => 'sekret', //in basic xampp: ''
'database' => 'my_app', //name of the database you want to connect to your project
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
]
],
If your database is connected correctly you then enter bin/cake bake
in the root folder of your project in a console window.
This should output something like this:
Welcome to CakePHP v3.1.6 Console
---------------------------------------------------------------
App : src
Path: /var/www/cakephp.dev/src/
PHP: 5.5.8
---------------------------------------------------------------
The following commands can be used to generate skeleton code for your application.
Available bake commands:
- all
- behavior
- cell
- component
- controller
- fixture
- form
- helper
- mailer
- migration
- migration_snapshot
- model
- plugin
- shell
- shell-helper
- template
- test
By using `cake bake [name]` you can invoke a specific bake task.
For simplicity purposes we are going to bake everything with the default settings. To do this you enter
cake bake all
This will output something along those lines:
Welcome to CakePHP v3.2.11 Console
---------------------------------------------------------------
App : src
Path: C:\xampp\htdocs\tipping\src\
PHP : 5.6.15
---------------------------------------------------------------
Bake All
---------------------------------------------------------------
Possible model names based on your database:
- users
- blogs
Run `cake bake all [name]` to generate skeleton files.
By running cake bake all <modelNameYouWantToBake>
the model, table, controller, fixture and view files are created.
Run this for every possible model name and you have a functioning Project with basic CRUD options.
Now you can open your browser and see how it looks and start extending the project by your own logic