Search code examples
symfonysilex

Mount/Use controller in console


In a Silex console command I want to perform a sub-request on a controller route. Unfortunately routes don't seem to be imported when executing a command by default. I always get the following error:

Unable to generate a URL for the named route "xyz_subject_method" as such route does not exist

Therefore I tried to mount the defining controller from within my Console class by using $this->mount('/prefix', Controller::mount($this)) inside the Console constructor. This has no effect.

Is there any way to access controllers directly from a console command?


Solution

  • After mounting a controller inside the Console constructor you need to flush the controller collection by using $this->flush();

    So mounting the controller should look like this:

    $this->mount('/prefix', Controller::mount($this));
    $this-flush();