Reputation: 6471
I created a Controller and named the class DataTableController
. But now I get an error message
InvalidArgumentException
Cannot determine controller argument for "App\Controller\DataTableController::usersAction()": the $request argument is type-hinted with the non-existent class or interface: "App\Controller\Request". Did you forget to add a use statement?
How do I find out what kind of use statement I need to add?
<?php
namespace App\Controller;
use DataTables\DataTablesInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Routing\Annotation\Route;
/**
*
* @Route("/users", name="users")
*
* @param Request $request
* @param DataTablesInterface $datatables
* @return JsonResponse
*/
class DataTableController extends Controller
{
const ID = 'users';
public function usersAction(Request $request, DataTablesInterface $datatables): JsonResponse
{
try {
// Tell the DataTables service to process the request,
// specifying ID of the required handler.
$results = $datatables->handle($request, 'users');
return $this->json($results);
}
catch (HttpException $e) {
// In fact the line below returns 400 HTTP status code.
// The message contains the error description.
return $this->json($e->getMessage(), $e->getStatusCode());
}
}
}
Upvotes: 1
Views: 9626
Reputation: 383
I was able to find it by running:
php ./bin/console debug:autowiring
In addition, you can run the same command but with a --show-private
flag:
php ./bin/console debug:container --show-private
I hope this helps.
Upvotes: 4
Reputation: 1879
An use
is missing:
use Symfony\Component\HttpFoundation\Request;
JsonResponse
, HttpException
mays be missing too. Use your IDE autocomplete to import these classes
Upvotes: 3