Closed jorgeale90 closed 3 years ago
Can I closed that issue?
I really dont understand, plz Ask a question or I will close the issue.
First of all, forgive me, my English is not very good. My question is how can I solve the error shown above.
The solution I made I don't know if it's all right
/**
* @var EntityManagerInterface
*/
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* @Route("/posts/", name="admin_posts", methods={"GET"})
* @IsGranted("IS_AUTHENTICATED_FULLY")
*/
public function posts(Request $request, PaginatorInterface $paginator, FilterBuilderUpdaterInterface $query_builder_updater)
{
$filterBuilder = $this->em->getRepository(Post::class)
->createQueryBuilder('c')
->orderBy('c.date_created', 'DESC');
$form = $this->get('form.factory')->create(PostFilterType::class);
if ($request->query->has($form->getName())) {
$form->submit($request->query->get($form->getName()));
$query_builder_updater->addFilterConditions($form, $filterBuilder);
}
$query = $filterBuilder->getQuery();
$pagination = $paginator->paginate(
$query,
$request->query->get('page', 1)/*page number*/,
10/*limit per page*/
);
return $this->render('dashboard/posts.html.twig', array(
'form' => $form->createView(),
'pagination' => $pagination
));
}
Service "doctrine.orm.entity_manager" not found: even though it exists in the app's container, the container inside "App\Controller\DashboardController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "serializer", "session" and "twig" services. Try using dependency injection instead.
class DashboardController extends AbstractController { /**
@IsGranted("IS_AUTHENTICATED_FULLY") */ public function posts(Request $request, PaginatorInterface $paginator, PostRepository $postRepository): Response { if ($postRepository->findAll() == null) { $flashBag = $this->get('session')->getFlashBag(); $flashBag->add('app_warning','No hay Post del Blog almacenados en la Base de Datos!!!'); }
} }