Php 如何使用条令(Symfony 4)将mysql数据库中的数据获取到datatable中?

Php 如何使用条令(Symfony 4)将mysql数据库中的数据获取到datatable中?,php,mysql,symfony,datatable,doctrine,Php,Mysql,Symfony,Datatable,Doctrine,如下图所示,我的表格由数组中的数据填充: public function showAction(Request $request) { $table = $this->createDataTable() ->add('firstName', TextColumn::class) ->add('lastName', TextColumn::class) ->createAdapter(ArrayAdapter::class, [

如下图所示,我的表格由数组中的数据填充:

  public function showAction(Request $request)
  {

    $table = $this->createDataTable()
    ->add('firstName', TextColumn::class)
    ->add('lastName', TextColumn::class)
    ->createAdapter(ArrayAdapter::class, [
      ['firstName' => 'Cat', 'lastName' => 'Duck'],
      ['firstName' => 'Monkey', 'lastName' => 'Dog'],
    ])
    ->handleRequest($request);

    if ($table->isCallback()) {
      return $table->getResponse();
    }

    return $this->render('list.html.twig', ['datatable' => $table]);
  }
但是我需要的是直接从mySQL数据库获取数据。我用教义来尝试这个:

 public function showAction(Request $request)
  {
    $articles = $this->getDoctrine()->getRepository(Article::class)->findAll()->handleRequest($request);

    if ($articles ->isCallback()) {
      return $articles ->getResponse();
    }

    return $this->render('list.html.twig', ['datatable' => $articles]);
  }
但我有一个错误:

未捕获的PHP异常Symfony\Component\Debug\Exception\FatalThrowableError:“调用数组上的成员函数handleRequest()”位于/Users/work/project/src/Controller/DataTableController.PHP第27行

我也试着这样写:

  public function showAction(Request $request)
  {
    $articles = $this->getDoctrine()->getRepository(Article::class)->findAll();

    return $this->render('list.html.twig', ['datatable' => $articles]);
  }
但这里我得到了一个错误:

参数1传递给 Omines\DataTablesBundle\Twig\DataTablesExtension::Omines\DataTablesBundle\Twig{closure}() 必须是Omines\DataTablesBundle\DataTable的实例,给定数组, 叫来 /Users/work/project/var/cache/dev/twig/0b/0bf4881c934fbecf72f2dfcacd298733196c8daa0e22d77f67fcdf0fee9f33e4.php 在线185


根据文件()

在第一个示例中,您需要执行以下操作:

public function showAction(Request $request)
{
    $table = $this->createDataTable()
    ->add('firstName', TextColumn::class)
    ->add('lastName', TextColumn::class)
    ->createAdapter(ORMAdapter::class, [
        'entity' => Article::class,
    ])
    ->handleRequest($request);

    if ($table->isCallback()) {
        return $table->getResponse();
    }

    return $this->render('list.html.twig', ['datatable' => $table]);
}
别忘了在课堂上添加以下内容:

use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;

根据文件()

在第一个示例中,您需要执行以下操作:

public function showAction(Request $request)
{
    $table = $this->createDataTable()
    ->add('firstName', TextColumn::class)
    ->add('lastName', TextColumn::class)
    ->createAdapter(ORMAdapter::class, [
        'entity' => Article::class,
    ])
    ->handleRequest($request);

    if ($table->isCallback()) {
        return $table->getResponse();
    }

    return $this->render('list.html.twig', ['datatable' => $table]);
}
别忘了在课堂上添加以下内容:

use Omines\DataTablesBundle\Adapter\Doctrine\ORMAdapter;

这是一个完美的帮助这是一个完美的帮助