本文介绍了带有DataTables Omines捆绑包的错误Symfony 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将想知道如何使DataTables捆绑包工作,因为我无法使其工作.
I will want to know how to make the DataTables bundle works because I have not been able to make it work.
我执行了此命令"composer require omines/datatables-bundle".此后,我执行了"php bin/控制台资产:安装".我还添加了依赖项.
I executed this command "composer require omines/datatables-bundle".After this, I executed "php bin/console assets:install".I also added the dependencies.
但是当我进入我的页面时,出现此错误,您已请求不存在的服务"Omines \ DataTablesBundle \ DataTableFactory".
But when i go on my page i have this error you have requested a non-exist service "Omines \ DataTablesBundle \ DataTableFactory".
你能帮我吗?
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\AdminUserFormType;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Omines\DataTablesBundle\Column\TextColumn;
use Symfony\Component\Routing\Annotation\Route;
use Omines\DataTablesBundle\Adapter\ArrayAdapter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Omines\DataTablesBundle\Controller\DataTablesTrait;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class UsersController extends Controller
{
use DataTablesTrait;
/**
* @Route("/admin/user/test", name="users_test")
*/
public function usersTest(Request $request){
$table = $this->createDataTable()
->add('firstName', TextColumn::class)
->add('lastName', TextColumn::class)
->createAdapter(ArrayAdapter::class, [
['firstName' => 'Donald', 'lastName' => 'Trump'],
['firstName' => 'Barack', 'lastName' => 'Obama'],
])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('users/test.html.twig', ['datatable' => $table]);
}
}
推荐答案
<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\AdminUserFormType;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Omines\DataTablesBundle\Column\TextColumn;
use Symfony\Component\Routing\Annotation\Route;
use Omines\DataTablesBundle\Adapter\ArrayAdapter;
use Symfony\Component\HttpFoundation\JsonResponse;
use Omines\DataTablesBundle\DataTableFactory;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class UsersController extends Controller
{
protected datatableFactory;
public function __construct(DataTableFactory $datatableFactory) {
$this->datatableFactory = $datatableFactory;
}
/**
* @Route("/admin/user/test", name="users_test")
*/
public function usersTest(Request $request){
$table = $this->datatableFactory->create([])
->add('firstName', TextColumn::class)
->add('lastName', TextColumn::class)
->createAdapter(ArrayAdapter::class, [
['firstName' => 'Donald', 'lastName' => 'Trump'],
['firstName' => 'Barack', 'lastName' => 'Obama'],
])
->handleRequest($request);
if ($table->isCallback()) {
return $table->getResponse();
}
return $this->render('users/test.html.twig', ['datatable' => $table]);
}
}
这篇关于带有DataTables Omines捆绑包的错误Symfony 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!