Ikbel
Ikbel

Reputation: 63

How to Do backend and Frontend architectures in cakephp 3.0?

How separate the backend and frontend (controllers, view, layout) in the same application share the models in CakePHP 3 ?

Upvotes: 3

Views: 1759

Answers (1)

eclaude
eclaude

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

Related Questions