MissingControllerException for DController in CakePHP 5.2 and HTTP 500 After Custom ErrorHandler

Hello CakePHP Community,

I’m working with CakePHP 5.2 and encountering issues with my custom DController. I’ve defined routes in config/routes.php for URLs like /d/:dimensionSlug and /d/:dimensionSlug/sd/:subdimensionSlug. However, when accessing /d/, I receive the following error:

MissingControllerException: Controller class `d` could not be found.
  • this is my DController.php (src/Controller/DController.php):
<?php
namespace App\Controller;

use App\Controller\AppController;
use Cake\Http\Exception\NotFoundException;

class DController extends AppController
{
    public function index($dimensionSlug = null)
    {
        if (!$dimensionSlug) {
            throw new NotFoundException(__('Dimension not specified.'));
        }

        return $this->redirect([
            'controller' => 'Pages',
            'action' => 'dimension',
            $dimensionSlug
        ]);
    }

    public function sd($dimensionSlug = null, $subdimensionSlug = null)
    {
        if ($dimensionSlug && $subdimensionSlug) {
            return $this->redirect([
                'controller' => 'Pages',
                'action' => 'dimension',
                $dimensionSlug,
                $subdimensionSlug
            ]);
        }

        throw new NotFoundException(__('Subdimension not specified.'));
    }
}
  • This are my Routes Configuration (config/routes.php): :
$builder->connect('/d', ['controller' => 'D', 'action' => 'index']);

$builder->connect(
    '/d/:dimensionSlug/sd/:subdimensionSlug',
    ['controller' => 'D', 'action' => 'sd'],
    [
        'pass' => ['dimensionSlug', 'subdimensionSlug'],
        'dimensionSlug'    => '[^/]+',
        'subdimensionSlug' => '[^/]+'
    ]
);

$builder->connect(
    '/d/:dimensionSlug',
    ['controller' => 'D', 'action' => 'index'],
    [
        'pass' => ['dimensionSlug'],
        'dimensionSlug' => '[^/]+'
    ]
);

  • Error Log Excerpt:
MissingControllerException: Controller class `d` could not be found.
  • Steps I’ve Taken:
  • Verified that DController.php is correctly named (uppercase “D”) and located in src/Controller/.
  • Defined specific routes before general ones in routes.php.
  • Ran composer dump-autoload and cleared CakePHP’s cache.

Any guidance or suggestions would be greatly appreciated!

Thank you!

CakePHP 5.2 has not been released yet, the latest release is 5.1.2

So either you are running the 5.next branch or you have a typo in your provided version :wink:


Anyway, can you try and open up the DebugKit Routes tab? It should show you which route was matched for your given URL as a highlighted section.

With that you can at least make sure, that the correct Route has matched.

Not sure if Cake routing treats /d and /d/ as different things, but that would be my first guess.