omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
252 stars 113 forks source link

Attempted to load class "OptionsResolver" from namespace "Symfony\Component\OptionsResolver". Did you forget a "use" statement for another namespace? #173

Closed adsazad closed 3 years ago

adsazad commented 3 years ago

getting this error in symfony 5 "Attempted to load class "OptionsResolver" from namespace "Symfony\Component\OptionsResolver". Did you forget a "use" statement for another namespace?"

My code is:

 public function myProducts(Request $request, DataTableFactory $dtf) {
        $em = $this->getDoctrine()->getManager();
        $user = $this->getUser();
        $user = $em->getRepository(User::class)->findOneBy(['id' => $user->getId()]);
        $datatable = $dtf->create()
                ->add('name', TextColumn::class, ['label' => 'Name'])
                ->createAdapter(ORMAdapter::class, [
                    'entity' => Product::class,
                    'query' => function (QueryBuilder $builder) {
                        $builder
                        ->select('p')
                        ->from(Product::class, 'p')
                        ;
                    },
                ])
                ->handleRequest($request);

        if ($datatable->isCallback()) {
            return $datatable->getResponse();
        }

        return $this->render('user/myProduct.html.twig', [
                    'datatable' => $datatable,
        ]);
    }
adsazad commented 3 years ago

Symfony Shows error at

 $datatable = $dtf->create()
adsazad commented 3 years ago

symfony/options-resolver needed to to avoid this error