Akhirnya, kita sampai pada materi inti yaitu membuat aplikasi CRUD (Create, Read, Update, Delete) berdasarkan tabel “buku”. Pada proses pembuatan CRUD ini akan digunakan plugin “bake” yang merupakan plugin penting karena plugin ini bisa membuat file controller, model, dan view secara otomatis.
A. Membuat Sebuah Pola MVC Dengan Plugin “bake”
Untuk membuat file MVC secara otomatis diperlukan plugin “bake”. Kita wajib mengetes plugin “bake” di terminal dengan perintah :
bin/cake bake --help
Current Paths:
* app: src/
* root: /opt/lampp/htdocs/cake/app/
* core: /opt/lampp/htdocs/cake/app/vendor/cakephp/cakephp/
Available Commands:
Bake:
- bake all
- bake behavior
- bake cell
- bake command
- bake component
- bake controller
- bake controller all
- bake fixture
- bake fixture all
- bake form
- bake helper
- bake mailer
- bake middleware
- bake model
- bake model all
- bake plugin
- bake shell
- bake shell_helper
- bake task
- bake template
- bake template all
- bake test
Migrations:
- bake migration
- bake migration_diff
- bake migration_snapshot
- bake seed
To run a command, type `cake command_name [args|options]`
To get help on a specific command, type `cake command_name --help
Bila muncul seperti di atas, maka perintah bake sudah bisa digunakan.
B. Meng-generate Pola MVC Untuk Aplikasi CRUD
Buka terminal lalu ketik perintah berikut :
bin/cake bake all buku
setelah seluruh file berhasil di-generate maka kita harus menjalankan server untuk melihat hasilnya.
bin/cake server
buka alamat “http://localhost:8765/buku” maka akan muncul tampilan berikut :
