4

I am developing a symfony 5 web project and I have to make as an university project. I started from the admin part and I used the bundle easyadmin by easycorp. I made the crud first all good but then by advancing in the project I started receiving below error

EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::setCrudId(): Argument #1 ($crudId) must be of type string, null given, called in /Applications/MAMP/htdocs/appmusic/vendor/twig/twig/src/Extension/CoreExtension.php on line 1541

and I have no clue from it is coming. Started another project and again same issue.

Please I need your help if you guys may come in handy. Thank you very much

oguzhancerit
  • 1,436
  • 1
  • 16
  • 27
  • Which version of Easy Admin bundle? Maybe more information about Entity and Admin Controller will help. – Ucay Dec 29 '20 at 07:39
  • Please share more details such that others could reproduce your problem – Nico Haase Dec 29 '20 at 08:42
  • For example, are you using v3.2.0 of the EasyAdminBundle which has deprecated `setCrudId`? – Nico Haase Dec 29 '20 at 08:44
  • I am using the 3.2.0 version of easy admin and the Symfony version is 5.2. The problem now is following even to new projects. I tried to reproduce the work done but once I make the admin cruds the error starts popping up and it goes to all the way whenever I try to access any admin crud on my dashboard. And I can't really really give more informations because actually that's the only thing shown by the Symfony debugger – S P A C E D O U T Dec 29 '20 at 09:28
  • @NicoHaase I experience this error after completing the Step 9.1 of the Symfony Fast Track book (https://symfony.com/doc/current/the-fast-track/en/9-backend.html). I also checked out the code straight from the book's Github repository and got the same error. It uses v3.2.3 of the EasyAdminBundle. – authentictech Aug 11 '21 at 13:43

1 Answers1

6

Faced the same problem with FastTrack.

First I removed the admin

$ symfony composer remove 'admin'

After I installed the latest

$ symfony composer req 'admin'

Not sure it's needed.

Solved by following https://github.com/EasyCorp/EasyAdminBundle/blob/master/UPGRADE.md look for Generating links to EasyAdmin pages

So now I use AdminUrlGenerator instead of CrudUrlGenerator

Now my DashboardController is class DashboardController extends AbstractDashboardController { private $adminUrlGenerator;

  public function __construct(AdminUrlGenerator $adminUrlGenerator)
  {
    $this->adminUrlGenerator = $adminUrlGenerator;
  }

  /**
   * @Route("/admin", name="admin")
   */
  public function index(): Response
  {
    $url = $this->adminUrlGenerator
        ->setController(ConferenceCrudController::class)
        //->setAction('edit')
        //->setEntityId(1)
        ->generateUrl();
    
    //$routeBuilder = $this->get(CrudUrlGenerator::class)->build();
    //$url = $routeBuilder->setController(ConferenceCrudController::class)->generateUrl();

      return $this->redirect($url);
      //return parent::index(); 
  }
  ...
ConstAxer
  • 61
  • 1
  • 2
  • Thanks. You saved me from weeks of headaches on this problem. I hope the Fast Track book & code gets updated. It may not come up for anyone else but I thought I'd add the tip for people to make sure they do not simply reload the same admin URL they were using before as it seems to be related to the old code and will still generate exceptions. Instead, load the page fresh at https://127.0.0.1:8000/admin – authentictech Sep 06 '21 at 18:12