How to place controller in subfolders in CakePhp3?
Asked Answered
H

3

7

I would like to place some of my controller classes in a subfolder (src/Controller/Admin/). Does anyone know how this can be made in CakePhp3?

Have answered 15/3, 2015 at 7:10 Comment(0)
H
6

Check the routing section in the cookbook http://book.cakephp.org/3.0/en/development/routing.html#prefix-routing

Horror answered 15/3, 2015 at 19:52 Comment(1)
I want to separate my controller and place it in sub directory, Is it possible?Bruner
A
0

Sounds like you’re looking for Routing Prefixes

https://book.cakephp.org/3.0/en/development/routing.html#prefix-routing

Aftersensation answered 18/6, 2018 at 11:50 Comment(0)
M
0

This is for people that also want to add subfolders inside an already prefix subfolder.

This way you can have this structure:

src/Controller/Api/V1/BookingsController.php

BookingsController:

<?php
namespace App\Controller\Api\V1;

use App\Controller\AppController;

/**
 * V1
 */
class BookingsController extends AppController
{
    public function list()
    {
        die('here we are');
    }
}

routes.php

Router::prefix('api/v1', function (RouteBuilder $routes) {
  $routes->extensions(['json']);
  $routes->fallbacks(DashedRoute::class);
});
Maniacal answered 7/7, 2021 at 11:18 Comment(1)
and what will be the restful uri ?Sandie

© 2022 - 2024 — McMap. All rights reserved.