0

I'm using stwe/DatatablesBundle for symfony 2 (http://github.com/stwe/DatatablesBundle) (stable version v0.6.1) and getting the following error:

Catchable Fatal Error: Argument 1 passed to Sg\DatatablesBundle\Datatable\View\AbstractDatatableView::__construct() must be an instance of Symfony\Bundle\TwigBundle\TwigEngine, none given, called in G:\server\www\bongoapp\app\cache\dev\appDevDebugProjectContainer.php on line 418 and defined

I have tried following the answer here, but it is not working for me. What am I doing wrong? Code below and thanks in advance:

Generated datatable class:

namespace Bbd\BongoAppBundle\Datatables;

use Sg\DatatablesBundle\Datatable\View\AbstractDatatableView;

/**
 * Class ArtistDatatable
 *
 * @package Bbd\BongoAppBundle\Datatables
 */
 class ArtistDatatable extends AbstractDatatableView
{
/**
 * {@inheritdoc}
 */
public function buildDatatableView()
{
    $this->getFeatures()
                    ->setServerSide(true)
                    ->setProcessing(true);

            $this->getAjax()->setUrl($this->getRouter()->generate('artist_results'));

    $this->setStyle(self::BOOTSTRAP_3_STYLE);


    $this->getColumnBuilder()
            ->add('id', 'column', array('title' => 'Id',))
            ->add('name', 'column', array('title' => 'Name',))
            ->add('bangla_name', 'column', array('title' => 'Bangla_name',))
            ->add('birth_place', 'column', array('title' => 'Birth_place',))
            ->add('priority', 'column', array('title' => 'Priority',))
            ->add('bday', 'column', array('title' => 'Bday',))
            ->add('bmonth', 'column', array('title' => 'Bmonth',))
            ->add('byear', 'column', array('title' => 'Byear',))
            ->add('sex', 'column', array('title' => 'Sex',))
            ->add('dod_day', 'column', array('title' => 'Dod_day',))
            ->add('dod_month', 'column', array('title' => 'Dod_month',))
            ->add('dod_year', 'column', array('title' => 'Dod_year',))
            ->add('bio_english', 'column', array('title' => 'Bio_english',))
            ->add('bio_bangla', 'column', array('title' => 'Bio_bangla',))
            ->add('real_name', 'column', array('title' => 'Real_name',))
            ->add('debut', 'column', array('title' => 'Debut',))
            ->add('graphics.id', 'column', array('title' => 'Graphics Id',))
            ->add('graphics.thumbnail', 'column', array('title' => 'Graphics Thumbnail',))
            ->add('graphics.poster', 'column', array('title' => 'Graphics Poster',))
            ->add('graphics.feature', 'column', array('title' => 'Graphics Feature',))
            ->add('graphics.gallery', 'column', array('title' => 'Graphics Gallery',))
            ;
}

/**
 * {@inheritdoc}
 */
public function getEntity()
{
    return 'Bbd\BongoAppBundle\Entity\Artist';
}

/**
 * {@inheritdoc}
 */
public function getName()
{
    return 'artist_datatable';
}
}

Controller

public function indexAction()
{
    $postDatatable = $this->get("bbd_datatables.artist");

    return array(
        "datatable" => $postDatatable,
    );
}

public function indexResultsAction()
{
    /**
     * @var \Sg\DatatablesBundle\Datatable\Data\DatatableData $datatable
     */
    $datatable = $this->get("bbd_datatables.datatable")->getDatatable($this->get("bbd_datatables.artist"));



    return $datatable->getResponse();
}

services.yml

  bbd_datatables.artist:
     class: Bbd\BongoAppBundle\Datatables\ArtistDatatable
     tags:
        - { name: bbd.datatable.view }

and index.html.twig

{% block content_content %}
{{ datatable_render_html(datatable) }}
{% endblock %}
{% block javascripts %}
{{ parent() }}
{{ datatable_render_js(datatable) }}
{% endblock %} 
Community
  • 1
  • 1
Samia Ruponti
  • 3,910
  • 12
  • 42
  • 62

2 Answers2

0

It seems like you've used the wrong tag.

bbd_datatables.artist:
   class: Bbd\BongoAppBundle\Datatables\ArtistDatatable
   tags:
      - { name: sg.datatable.view }

Look: https://github.com/stwe/DatatablesBundle/blob/master/Resources/doc/example.md#step-3-registering-your-datatables-class-as-a-service

Henrique Barcelos
  • 7,670
  • 1
  • 41
  • 66
  • ok thanks for your answer but im getting this.. Catchable Fatal Error: Argument 2 passed to Sg\DatatablesBundle\Datatable\View\AbstractDatatableView::__construct() must implement interface Symfony\Component\Translation\TranslatorInterface, none given – Samia Ruponti Jun 02 '15 at 18:24
  • Can you comment with the link to this bundle? It seems like it has more dependencies that need to be set. – Henrique Barcelos Jun 02 '15 at 18:25
  • its in the quetion but here its again for you .. http://github.com/stwe/DatatablesBundle – Samia Ruponti Jun 02 '15 at 18:26
  • sorry to bothery ou again but still getting this error : The controller must return a response (Array(datatable => Object(Bbd\BongoAppBundle\Datatables\ArtistDatatable)) given). – Samia Ruponti Jun 02 '15 at 19:12
  • ok i was wrong here, because i was calling index and that should return the object and when im visiting results (indexResultsAction) gettting this error: Notice: Undefined index: columns – Samia Ruponti Jun 02 '15 at 19:45
0

I could fix this by using the parent argument in the config:

bbd_datatables.artist:
    class: Bbd\BongoAppBundle\Datatables\ArtistDatatable
    parent: sg_datatables.datatable.abstract
    tags:
        - { name: sg.datatable.view }

This pulls the argument declaration required for the AbstractDatatableView.

althaus
  • 2,009
  • 2
  • 25
  • 33