APY / APYDataGridBundle

Symfony Datagrid Bundle
MIT License
492 stars 344 forks source link

Fix error empty route name #967

Open makoso opened 7 years ago

makoso commented 7 years ago

Fix error on requests that cannot access requested _route

DonCallisto commented 7 years ago

Hi, could you explain this? When _route is not available?

makoso commented 7 years ago

Hi @DonCallisto

I get this error when i need grid on page that has route parameters and grid isnt returned by gridGet reponse, because ineed more that one grid on this page i return it like this example:

  1. Create grid
  2. fire method isReadyForRedirect()
  3. assign to the template
  4. standard render it: {{ grid(contactPersons, 'APYDataGridBundle::blocks_js.jquery.html.twig') }}

if i dont have this changes i get error unable to generate route for name ""(empty) or in some times i get error of missing parameters to gereate route for current request (i use ajax) after this fix #967 i get good grid displayed but no working filtering because there is same problem, request dosnt contains all parameters see #968

Maybe is better to check it in constructor?

Regards.

DonCallisto commented 7 years ago

Sorry but I don't understand your use case. Do you have multiple grid on the same page? If page is the same, _route and other things should continue to work as expected. Can you isolate the problem in a repository so we can see exactly what's going on? To me is just strange that no route is setted.

b-enoit-be commented 6 years ago

@DonCallisto this actually happens on forwarded routes.

Fabien Potencier actually explained here that _route should not be used because it is only for debugging purpose.

b-enoit-be commented 6 years ago

In a similar issue, I did resolve it using the RequestStack instead:

/** @var Symfony\Component\HttpFoundation\RequestStack $requestStack -- can be DI'ed */
$gridManager->createGrid()
            ->setSource($source)
            ->setRouteUrl($requestStack->getMasterRequest()->getPathInfo());
DonCallisto commented 5 years ago

That makes sense but we should think how to solve this natively. I'll take a look when I have time otherwise feel free to open a PR.