Can anyone tell me what is the official way to create CRUD for admin back-end?
In CakePHP 2 the baked code was extended with 'admin_' before the function names and for the view files. In CakePHP it seems I can't find any direct information on how it's done anymore. The bake console doesn't ask for admin anymore. In this topic: https://github.com/cakephp/bake/issues/28 I see that they mention to use the --prefix extension but then the controller is placed in a separate /Admin folder while the CRUD functions keep having their normal name. And in some parts of the cookbook () I still see they mention functions like admin_view.
So can anyone tell me what is the official 'Cake'-way to do this from 3.2 on?
If you want to create Controller using cake bake. You can do this with below command:
bin/cake bake controller --prefix admin users
For view:
bin/cake bake template --prefix admin users
It creates the admin folder in the template directory, Then it creates the folder for users, then it includes the files. for admin prefix folder structure like
template/admin/users/index.ctp
See official cookbook documentation
Also In your config/routes.php add this:
Router::prefix('admin', function ($routes) {
$routes->connect('/', ['controller' => 'Users', 'action' => 'index']);
$routes->extensions(['json', 'xml']);
// All routes here will be prefixed with `/admin`
// And have the prefix => admin route element added.
$routes->fallbacks('DashedRoute');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With