Symfony 4.2 DI issue
Starting with Symfony 4.2, Controller is deprecated, recommending AbstractController to be used. However, by using AbstractController the 'old' way of getting the factory service no longer works.
Old: $datatable = $this->get('sg_datatables.factory')->create(EntityDatatable::class);
The new way to use the datatables factory is to use dependency injection in the constructor of the controller.
private $dtFactory;
private $dtResponse;
public function __construct(DatatableFactory $datatableFactory, DatatableResponse $datatableResponse)
{
$this->dtFactory = $datatableFactory;
$this->dtResponse = $datatableResponse;
}
This allows to access the factory:
$datatable = $this->dtFactory->create(EntityDatatable::class);
And the response:
$responseService = $this->dtResponse; in the Ajax response portion of the function.
However, now, Symfony complains:
Cannot autowire service "App\Controller\Support\SupportController": argument "$datatableFactory" of method "__construct()" references class "Sg\DatatablesBundle\Datatable\DatatableFactory" but no such service exists. You should maybe alias this class to the existing "sg_datatables.factory" service.
The fix for this is in the services.yaml to add the following:
Sg\DatatablesBundle\Datatable\DatatableFactory:
alias: sg_datatables.factory
Sg\DatatablesBundle\Response\DatatableResponse:
alias: sg_datatables.response
At this point, everything should be working properly.
Hi ! I know someone else tell that but I can't find response. I'm on Symfony 4.1 and I can't use Datatable bundle
#> php bin/console sg:datatable:generate AppBundle:Post There are no commands defined in the "sg:datatable" namespace. Did you mean this? doctrine:database
Thank's by advance
Hi ! I know someone else tell that but I can't find response. I'm on Symfony 4.1 and I can't use Datatable bundle
#> php bin/console sg:datatable:generate AppBundle:Post There are no commands defined in the "sg:datatable" namespace. Did you mean this? doctrine:database
Thank's by advance
I believe this is for a different question. The above is for Symfony 4.2 that deprecated Controller for AbstractController and the modifications necessary to allow proper dependency injection.
In addition the route annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
got superseded by a single
use Symfony\Component\Routing\Annotation\Route;
@Seb33300 @stwe guys plz check and merge Symfony 4(actual for Symfony 5) issues. Have to use forks =(
If you are encountering issue, feel free to submit a pull request.
@Seb33300 #762 #833 #922 I haven't access for submit pull requests. plz check this PRs and merge