简体   繁体   English

Symfony 2可捕获的致命错误:传递给Sg \\ DatatablesBundle \\ Datatable \\ :: __ construct()的参数1必须是的实例

[英]Symfony 2 Catchable Fatal Error: Argument 1 passed to Sg\DatatablesBundle\Datatable\::__construct() must be an instance of

I'm using stwe/DatatablesBundle for symfony 2 ( http://github.com/stwe/DatatablesBundle ) (stable version v0.6.1) and getting the following error: 我将stwe / DatatablesBundle用于symfony 2( http://github.com/stwe/DatatablesBundle )(稳定版v0.6.1),并收到以下错误:

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 可捕获的致命错误:传递给Sg \\ DatatablesBundle \\ Datatable \\ View \\ AbstractDatatableView :: __ construct()的参数1必须是Symfony \\ Bundle \\ TwigBundle \\ TwigEngine的实例,未给出,在G:\\ server \\ www \\ bongoapp \\ app中调用\\ cache \\ dev \\ appDevDebugProjectContainer.php在第418行并已定义

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 services.yml

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

and index.html.twig index.html.twig

{% block content_content %}
{{ datatable_render_html(datatable) }}
{% endblock %}
{% block javascripts %}
{{ parent() }}
{{ datatable_render_js(datatable) }}
{% endblock %} 

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 看: https : //github.com/stwe/DatatablesBundle/blob/master/Resources/doc/example.md#step-3-registering-your-datatables-class-as-a-service

I could fix this by using the parent argument in the config: 我可以通过在配置中使用parent参数来解决此问题:

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 . 这将提取AbstractDatatableView所需的参数声明。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony2:ContextErrorException:可捕获的致命错误:传递给[…] :: __ construct()的参数1必须实现接口[…]没有给出 - Symfony2: ContextErrorException: Catchable Fatal Error: Argument 1 passed to […]::__construct() must implement interface […] none given 可捕获的致命错误:传递给“…\\ FormType :: __ construct()的参数1必须实现接口 - Catchable Fatal Error: Argument 1 passed to "…\FormType::__construct() must implement interface 可捕获的致命错误:传递给Controller :: __ construct()的参数1必须是Doctrine \\ ORM \\ EntityManager的实例,未给出任何实例,称为 - Catchable Fatal Error: Argument 1 passed to Controller::__construct() must be an instance of Doctrine\ORM\EntityManager, none given, called 可捕获的致命错误:传递给UserBundle \\ Form \\ UserType :: __ construct()的参数2必须是实例? - Catchable Fatal Error: Argument 2 passed to UserBundle\Form\UserType::__construct() must be an instance ? 可捕获的致命错误:传递给AppBundle \\ Form \\ TagType :: __ construct()的参数1必须是Doctrine \\ ORM \\ EntityRepository的实例,未给出任何实例, - Catchable Fatal Error: Argument 1 passed to AppBundle\Form\TagType::__construct() must be an instance of Doctrine\ORM\EntityRepository, none given, 可捕获的致命错误:传递给 Album\Controller\AlbumController::__construct() 的参数 1 必须是 Album\Model\AlbumTable 的实例,没有给出 - Catchable fatal error: Argument 1 passed to Album\Controller\AlbumController::__construct() must be an instance of Album\Model\AlbumTable, none given Symfony服务容器-可捕获的致命错误-传递给构造的参数 - Symfony service container - Catchable Fatal Error - Argument passed to construct 可捕获的致命错误:传递给Symfony :: render()的参数3必须是Symfony \\ .. \\ Response的实例,给定数组 - Catchable Fatal Error: Argument 3 passed to Symfony::render() must be an instance of Symfony\..\Response, array given Symfony 2嵌入式表单:可捕获的致命错误:传递给Entity的参数1 :: addProperty必须是XX \\ MyClass的一个实例,给出的数组 - Symfony 2 Embedded Forms: Catchable Fatal Error: Argument 1 passed to Entity::addProperty must be an instance of XX\MyClass, array given 可捕获的致命错误:传递给\\ Entity \\ Image :: setFile()的参数1必须是Symfony \\ Component \\ HttpFoundation \\ File \\ UploadedFile的实例, - Catchable Fatal Error: Argument 1 passed to \Entity\Image::setFile() must be an instance of Symfony\Component\HttpFoundation\File\UploadedFile,
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM