I am trying to use omines/datatables-bundle in symfony 5.
I follow https://omines.github.io/datatables-bundle/#introduction :
composer require omines/datatables-bundle
php bin/console assets:install
It is my code:
<?php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentHttpFoundationRequest;
use SymfonyComponentRoutingAnnotationRoute;
use AppEntityUsuarios;
use OminesDataTablesBundleAdapterArrayAdapter;
use OminesDataTablesBundleColumnTextColumn;
use OminesDataTablesBundleDataTableFactory;
use OminesDataTablesBundleAdapterDoctrineORMAdapter;
class UsuariosController extends AbstractController
{
protected $datatableFactory;
public function __construct(DataTableFactory $datatableFactory) {
$this->datatableFactory = $datatableFactory;
}
/**
* @Route("/list", name="list")
*/
public function list(Request $request )
{
$table = $this->dataTableFactory->create()
->add('apellido', TextColumn::class)
->add('nombre', TextColumn::class)
->add('usuario', TextColumn::class)
->createAdapter(ORMAdapter::class, [
'entity' => Usuario::class,
])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('index.html.twig', ['datatable' => $table]);
}
}
This is my composer.json:
{
"type": "project",
"license": "proprietary",
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.2.5",
"ext-ctype": "*",
"ext-iconv": "*",
"composer/package-versions-deprecated": "1.11.99.1",
"doctrine/annotations": "^1.11",
"doctrine/doctrine-bundle": "^2.2",
"doctrine/doctrine-migrations-bundle": "^3.0",
"doctrine/orm": "^2.8",
"omines/datatables-bundle": "^0.5.2",
"symfony/console": "5.2.*",
"symfony/dotenv": "5.2.*",
"symfony/flex": "^1.3.1",
"symfony/framework-bundle": "5.2.*",
"symfony/proxy-manager-bridge": "5.2.*",
"symfony/twig-bundle": "5.2.*",
"symfony/yaml": "5.2.*"
},
"require-dev": {
"symfony/maker-bundle": "^1.27"
},
"config": {
"optimize-autoloader": true,
"preferred-install": {
"*": "dist"
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"App\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"App\Tests\": "tests/"
}
},
"replace": {
"symfony/polyfill-ctype": "*",
"symfony/polyfill-iconv": "*",
"symfony/polyfill-php72": "*"
},
"scripts": {
"auto-scripts": {
"cache:clear": "symfony-cmd",
"assets:install %PUBLIC_DIR%": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
"conflict": {
"symfony/symfony": "*"
},
"extra": {
"symfony": {
"allow-contrib": false,
"require": "5.2.*"
}
}
}
I am getting:
Cannot autowire service "AppControllerUsuariosController": argument "$datatableFactory" of method "__construct()" references class "OminesDataTablesBundleDataTableFactory" but no such service exists
If I run php bin/console cache:clear I get:
Cannot autowire service "AppControllerUsuariosController": argument "$datatableFactory" of method "__construct()" references class "OminesDataTablesBundleDataTa
bleFactory" but no such service exists.
There is nothing like omines datatable or DataTableFactoryInterface running bin/console debug:container, but when I installed it I did not get any error.
I followed:
Error Symfony 4 with DataTables Omines bundle and How to subscribe to the DataTableFactory service? ( I do not understand it ) and https://github.com/omines/datatables-bundle/commit/cd9b93eac9ef4fd3c1459305c71ca6e2ac0c444e
I will appreciate your help.
Finally, is there some bundle to use a gride like datatables in symfony 5 ? and is there some omines datatable documentation ? https://omines.github.io/datatables-bundle is very insufficient for me.
Thank you.
SOLVED: Install symfony new project width --full option. Thank you Cerard.
question from:
https://stackoverflow.com/questions/65649554/omines-datatables-in-symfony-5-does-not-work