Reputation: 63
How separate the backend and frontend (controllers, view, layout) in the same application share the models in CakePHP 3 ?
Upvotes: 3
Views: 1759
Reputation: 886
if you use bin/cake bake
in your terminal, you can add --prefix=Backend
ex controller: bin/cake bake controller NameOfYourTable --prefix=Backend
ex template: bin/cake bake template NameOfYourTable --prefix=Backend
CakePHP will create the subfolder ./src/Controller/Backend/NameOfYourTable
with the good namespace namespace App\Controller\Backend;
and ./src/Template/Backend/NameOfYourTable/
with index.ctp
, add.ctp
, edit.ctp
, view.ctp
And add the prefix your urls in routes.php
ex url: www.domain.tld/backend/nameofyourcontroller/
Router::prefix('backend', function($routes) {
$routes->connect(
'/',
['controller' => 'NameOfYourController', 'action' => 'index']
);
$routes->connect(
'/:controller',
['action' => 'index'],
['routeClass' => 'InflectedRoute']
);
$routes->connect(
'/:controller/:action/*',
[],
['routeClass' => 'InflectedRoute']
);
});
Upvotes: 1