Firstly thank you Mr. dakota for your kind and quick response.
Please see my UserGroupsController code below.
I have generated code in CakePHP 3.8 using bake, and the code works fine if I access with URL like <app_root>/user_groups/* and failed as above question if accessed with URL <app_root>/usergroups/* .
Tried again <app_root>/user_groups/* with CakePHP 4.0.1 , it says Cake\Http\Exception\MissingControllerException
Documentation said that we can access it either way (ver 3.x doc), but seem only the way with underscore works (in ver 3.x only). Is it a bug?
<?php
declare(strict_types=1);
namespace App\Controller;
class UserGroupsController extends AppController
{
public function index()
{
$this->paginate = [
//'contain' => ['Leaders', 'UpperGroups'],
];
$userGroups = $this->paginate($this->UserGroups);
$this->set('UGController', compact($this));
$this->set(compact('userGroups'));
}
public function view($id = null)
{
$userGroup = $this->UserGroups->get($id, [
'contain' => ['Leaders', 'UpperGroups', 'Users'],
]);
$this->set('userGroup', $userGroup);
}
public function add()
{
$userGroup = $this->UserGroups->newEmptyEntity();
if ($this->request->is('post')) {
$userGroup = $this->UserGroups->patchEntity($userGroup, $this->request->getData());
if ($this->UserGroups->save($userGroup)) {
$this->Flash->success(__('The user group has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The user group could not be saved. Please, try again.'));
}
$leaders = $this->UserGroups->Leaders->find('list', ['limit' => 200]);
$upperGroups = $this->UserGroups->UpperGroups->find('list', ['limit' => 200]);
$this->set(compact('userGroup', 'leaders', 'upperGroups'));
}
public function edit($id = null)
{
$userGroup = $this->UserGroups->get($id, [
'contain' => [],
]);
if ($this->request->is(['patch', 'post', 'put'])) {
$userGroup = $this->UserGroups->patchEntity($userGroup, $this->request->getData());
if ($this->UserGroups->save($userGroup)) {
$this->Flash->success(__('The user group has been saved.'));
return $this->redirect(['action' => 'index']);
}
$this->Flash->error(__('The user group could not be saved. Please, try again.'));
}
$leaders = $this->UserGroups->Leaders->find('list', ['limit' => 200]);
$upperGroups = $this->UserGroups->UpperGroups->find('list', ['limit' => 200]);
$this->set(compact('userGroup', 'leaders', 'upperGroups'));
}
public function delete($id = null)
{
$this->request->allowMethod(['post', 'delete']);
$userGroup = $this->UserGroups->get($id);
if ($this->UserGroups->delete($userGroup)) {
$this->Flash->success(__('The user group has been deleted.'));
} else {
$this->Flash->error(__('The user group could not be deleted. Please, try again.'));
}
return $this->redirect(['action' => 'index']);
}
}