I have a plugin where in an admin template I create an Ajax call to custom controller to get some data.
After the upgrade to v6.6 the call returns 404 - no route found. Is still possible to do this and if yes where I can find example how to do it? All links I found are for the Storefront.
<?php declare(strict_types=1);
namespace Swag\directory_name\Administration\Controller;
// lot of use classes next
#[Route(defaults: ['_routeScope' => ['api']])]
/**
* @author
*/
class OrderController extends AbstractController
{
// some variables
// then the constructor with lot of parameters in it
// and one of my public methods looking like this:
#[Route(path: '/api/company_name/check_order', name: 'api.action.company_name.check_order', defaults: ['auth_required' => false, 'XmlHttpRequest' => true], methods: ['POST', 'GET'])]
/**
* description here, then legacy route
* @Route("/api/company_name/check_order", name="api.action.company_name.check_order", defaults={"auth_required"=false, "XmlHttpRequest"=true}, methods={"GET", "POST"})
*
* @param Request $request
* @param Context $context
*
* @return JsonResponse
*/
public function checkForOrder(Request $request, Context $context)
{
...
// and return JsonResponse at the end.
}
}
That is all. Tested on version 6.6.1.0. I hope this can help you!
Regards!
PS - may be the only difference is you are using „-“ in the route, I use „_“. I am not sure your is wrong, but you can try to replace it.