omines / datatables-bundle

DataTables bundle for Symfony
https://omines.github.io/datatables-bundle/
MIT License
252 stars 113 forks source link

Notice: Undefined offset: 0 #159

Closed evskorobogatij closed 4 years ago

evskorobogatij commented 4 years ago

Hi!

I try to output data to datatables:


    /**
     * @Route("/", name="admin_petition")
     */
    public function index(Request $request,DataTableFactory $dataTableFactory, LoggerInterface $logger)
    {

        $table = $this->createDataTable()
            ->add("name",TextColumn::class)
            ->add("description",TextColumn::class)
            ->add("created_at",DateTimeColumn::class,[
                'format' => 'd-m-Y',
            ])
            ->add('signers',NumberColumn::class)
            ->add('author',TextColumn::class,[
                //"field" => "autor.fam",
                "render" => function(string $value,Petition $petition){
                    $people = $petition->getAutor();
                    //return $people->getFam().' '.$people->getIm().' '.$people->getOt();
                    $id = $people->getId();
                    return (string)$people.' '."<a href=/admin/people/$id/info><i class=\"fas fa-search\"></i></a>";
                }
            ])
            ->add('petition_type',TextColumn::class,["field"=>"petition_type.name"])
            ->add('stad',TextColumn::class,[
                //"field"=>"stad.name",
                'render' => function(string $value,Petition $petition){
                    $stad = $petition->getStad();
                    return '<span class="label label-danger" >'.$stad->getName().'</span>';
                }

            ])
            ->add('buttons', TextColumn::class, [
                'render' => function(string $value,Petition $petition){
                    $id = $petition->getId();
                    return "<a href=/admin/petition/$id/info class=\"btn-primary btn\">Просмотр</a>";
                }
            ])
            ->createAdapter(ORMAdapter::class,[
                'entity' => Petition::class,
                'criteria' => [
                    function(QueryBuilder $builder){
                        $builder->select('p')->from(Petition::class,'p')->andWhere('p.initiative_class=:initiative_class')->setParameter('initiative_class','petition');
                    }
                ]
            ])
            ->handleRequest($request);

When count of records is 1 all is fine... but when records count is more then 1, error occured Notice: Undefined offset: 0

What can I do to fix that?

evskorobogatij commented 4 years ago

I replease 'criteria' by 'query' and it work fine.. Very very bad documentation....

curry684 commented 4 years ago

Very very bad documentation....

My apologies for this apparent oversight in our completely free software. PR's on the docs folder are of course also highly welcome.