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 insrc/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!