Dear all,
I have a WardsController with actions like below
public function initialize(): void {
parent::initialize();
$this->loadComponent('RequestHandler');
}
public function getWards($districtID) {
$query = $this->Wards->find('list')
->where(['district_id' => $districtID]);
$wardList = $query->toArray();
$this->set('wardsList', $wardList);
$this->viewBuilder()->setOption('serialize', ['wardsList']);
//$this->set('_serialize', array('wardsList'));
}
I have enabled the extensions in config/Route like below:
$routes->scope('/', function (RouteBuilder $builder) {
// Register scoped middleware for in scopes.
$builder->registerMiddleware('csrf', new CsrfProtectionMiddleware([
'httpOnly' => true,
]));
$builder->applyMiddleware('csrf');
$builder->setExtensions(['json', 'xml']);
}
When I connect to /wards/get-wards.json/1 i get missing method in controller.
If I leave the .json out of the url, then missing view class error returned.
Did I miss something? Thanks very much.