簡體   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

我將stwe / DatatablesBundle用於symfony 2( http://github.com/stwe/DatatablesBundle )(穩定版v0.6.1),並收到以下錯誤:

可捕獲的致命錯誤:傳遞給Sg \\ DatatablesBundle \\ Datatable \\ View \\ AbstractDatatableView :: __ construct()的參數1必須是Symfony \\ Bundle \\ TwigBundle \\ TwigEngine的實例,未給出,在G:\\ server \\ www \\ bongoapp \\ app中調用\\ cache \\ dev \\ appDevDebugProjectContainer.php在第418行並已定義

我已經嘗試按照這里的答案進行操作,但是它對我不起作用。 我究竟做錯了什么? 下面的代碼,在此先感謝:

生成的數據表類:

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';
}
}

控制者

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 }

index.html.twig

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

好像您使用了錯誤的標簽。

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

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

我可以通過在配置中使用parent參數來解決此問題:

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

這將提取AbstractDatatableView所需的參數聲明。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

相關問題 Symfony2:ContextErrorException:可捕獲的致命錯誤:傳遞給[…] :: __ construct()的參數1必須實現接口[…]沒有給出 可捕獲的致命錯誤:傳遞給“…\\ FormType :: __ construct()的參數1必須實現接口 可捕獲的致命錯誤:傳遞給Controller :: __ construct()的參數1必須是Doctrine \\ ORM \\ EntityManager的實例,未給出任何實例,稱為 可捕獲的致命錯誤:傳遞給UserBundle \\ Form \\ UserType :: __ construct()的參數2必須是實例? 可捕獲的致命錯誤:傳遞給AppBundle \\ Form \\ TagType :: __ construct()的參數1必須是Doctrine \\ ORM \\ EntityRepository的實例,未給出任何實例, 可捕獲的致命錯誤:傳遞給 Album\Controller\AlbumController::__construct() 的參數 1 必須是 Album\Model\AlbumTable 的實例,沒有給出 Symfony服務容器-可捕獲的致命錯誤-傳遞給構造的參數 可捕獲的致命錯誤:傳遞給Symfony :: render()的參數3必須是Symfony \\ .. \\ Response的實例,給定數組 Symfony 2嵌入式表單:可捕獲的致命錯誤:傳遞給Entity的參數1 :: addProperty必須是XX \\ MyClass的一個實例,給出的數組 可捕獲的致命錯誤:傳遞給\\ Entity \\ Image :: setFile()的參數1必須是Symfony \\ Component \\ HttpFoundation \\ File \\ UploadedFile的實例,
 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM