奏鸣曲缺少参数



当我尝试使用全新安装的奏鸣曲adminBUndle访问我的网站时,我遇到了此错误。我可以看到列表,我可以看到仪表板,但是如果我尝试添加帖子,我会收到此消息。

Sonata\AdminBundle\Admin\Admin::__construct() 缺少参数 1, 被叫入 C:\wamp\www\sonata\vendor\sonata-project\doctrine-orm-admin-bundle\Sonata\DoctrineORMAdminBundle\Model\ModelManager.php在第416行,定义于 C:\wamp\www\sonata\app\cache\dev\classes.php 行 8120

任何人都可以提供帮助????

好的,谢谢你的答案,有代码

Symfony 2.4.1实体

<?php
namespace TicClasseBundleEntity;
use SonataAdminBundleAdminAdmin;
use SonataAdminBundleDatagridListMapper;
use SonataAdminBundleDatagridDatagridMapper;
use SonataAdminBundleFormFormMapper;
use DoctrineORMMapping as ORM;
/**
 * Groupe
 *
 * @ORMTable()
 * @ORMEntity(repositoryClass="TicClasseBundleEntityGroupeRepository")
 */
class Groupe extends Admin
{
    /**
     * @var integer
     *
     * @ORMColumn(name="id", type="integer")
     * @ORMId
     * @ORMGeneratedValue(strategy="AUTO")
     */
    private $id;
    /**
     * @var string
     *
     * @ORMColumn(name="groupe", type="string", length=255)
     */
    private $groupe;
    /**
     * @var string
     *
     * @ORMColumn(name="enseignant", type="string", length=255)
     */
    private $enseignant;
    /**
     * @var string
     *
     * @ORMColumn(name="grepere", type="string", length=255)
     */
    private $grepere;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    /**
     * Set groupe
     *
     * @param string $groupe
     * @return Groupe
     */
    public function setGroupe($groupe)
    {
        $this->groupe = $groupe;
        return $this;
    }
    /**
     * Get groupe
     *
     * @return string 
     */
    public function getGroupe()
    {
        return $this->groupe;
    }
    /**
     * Set enseignant
     *
     * @param string $enseignant
     * @return Groupe
     */
    public function setEnseignant($enseignant)
    {
        $this->enseignant = $enseignant;
        return $this;
    }
    /**
     * Get enseignant
     *
     * @return string 
     */
    public function getEnseignant()
    {
        return $this->enseignant;
    }
    /**
     * Set grepere
     *
     * @param string $grepere
     * @return Groupe
     */
    public function setGrepere($grepere)
    {
        $this->grepere = $grepere;
        return $this;
    }
    /**
     * Get grepere
     *
     * @return string 
     */
    public function getGrepere()
    {
        return $this->grepere;
    }
     protected function configureFormFields(FormMapper $formMapper)
    {
        $formMapper
            ->add('enseignant', 'text',array('label'=>'Enseignants(es)'))
            ->add('groupe', 'text',array('label'=>'Groupe'))
            ->add('grepere', 'text',array('label'=>'Groupe Repere')) //if no type is specified, SonataAdminBundle tries to guess it
        ;
    }
    // Fields to be shown on filter forms
    protected function configureDatagridFilters(DatagridMapper $datagridMapper)
    {
        $datagridMapper
            ->add('enseignant')
            ->add('grepere')
        ;
    }
    // Fields to be shown on lists
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('enseignant')
            ->add('grepere')
            ->add('groupe')
        ;
    }
}

配置.yml

imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: @TicClasseBundle/Resources/config/admin.yml }
framework:
    #esi:             ~
    translator:      { fallback: "%locale%" }
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true
# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
        #yui_css:
        #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver, add the path in parameters.yml
        # e.g. database_path: "%kernel.root_dir%/data/data.db3"
        # path:     "%database_path%"
    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }
sonata_admin:
    title: Gestion de classe
sonata_block:
    default_contexts: [cms]
    blocks:
        # Enable the SonataAdminBundle block
        sonata.admin.block.admin_list:
            contexts:   [admin]
        # Your other blocks
sonata_doctrine_orm_admin:
    # default value is null, so doctrine uses the value defined in the configuration
    entity_manager: ~
    templates:
        form:
            - SonataDoctrineORMAdminBundle:Form:form_admin_fields.html.twig
        filter:
            - SonataDoctrineORMAdminBundle:Form:filter_admin_fields.html.twig
        types:
            list:
                array:      SonataAdminBundle:CRUD:list_array.html.twig
                boolean:    SonataAdminBundle:CRUD:list_boolean.html.twig
                date:       SonataAdminBundle:CRUD:list_date.html.twig
                time:       SonataAdminBundle:CRUD:list_time.html.twig
                datetime:   SonataAdminBundle:CRUD:list_datetime.html.twig
                text:       SonataAdminBundle:CRUD:base_list_field.html.twig
                trans:      SonataAdminBundle:CRUD:list_trans.html.twig
                string:     SonataAdminBundle:CRUD:base_list_field.html.twig
                smallint:   SonataAdminBundle:CRUD:base_list_field.html.twig
                bigint:     SonataAdminBundle:CRUD:base_list_field.html.twig
                integer:    SonataAdminBundle:CRUD:base_list_field.html.twig
                decimal:    SonataAdminBundle:CRUD:base_list_field.html.twig
                identifier: SonataAdminBundle:CRUD:base_list_field.html.twig
                currency:   SonataAdminBundle:CRUD:list_currency.html.twig
                percent:    SonataAdminBundle:CRUD:list_percent.html.twig
                choice:     SonataAdminBundle:CRUD:list_choice.html.twig
                url:        SonataAdminBundle:CRUD:list_url.html.twig
            show:
                array:      SonataAdminBundle:CRUD:show_array.html.twig
                boolean:    SonataAdminBundle:CRUD:show_boolean.html.twig
                date:       SonataAdminBundle:CRUD:show_date.html.twig
                time:       SonataAdminBundle:CRUD:show_time.html.twig
                datetime:   SonataAdminBundle:CRUD:show_datetime.html.twig
                text:       SonataAdminBundle:CRUD:base_show_field.html.twig
                trans:      SonataAdminBundle:CRUD:show_trans.html.twig
                string:     SonataAdminBundle:CRUD:base_show_field.html.twig
                smallint:   SonataAdminBundle:CRUD:base_show_field.html.twig
                bigint:     SonataAdminBundle:CRUD:base_show_field.html.twig
                integer:    SonataAdminBundle:CRUD:base_show_field.html.twig
                decimal:    SonataAdminBundle:CRUD:base_show_field.html.twig
                currency:   SonataAdminBundle:CRUD:base_currency.html.twig
                percent:    SonataAdminBundle:CRUD:base_percent.html.twig
                choice:     SonataAdminBundle:CRUD:show_choice.html.twig
                url:        SonataAdminBundle:CRUD:show_url.html.twig        

和管理员

services:
    sonata.admin.post:
        class: TicClasseBundleEntityGroupe
        tags:
            - { name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" }
        arguments:
            - ~
            - TicClasseBundleEntityGroupe
            - ~
        calls:
            - [ setTranslationDomain, [AcmeDemoBundle]]

萨克斯

您的实体类 Groupe 不正确。

  • 它不会扩展Sonata管理员类。

  • 方法configureListFieldsconfigureFormFieldsconfigureDatagridFilters不应该出现在这里。它们必须位于单独的管理类(模拟symfony控制器类)中

例:

<?php
namespace TicClasseBundleControllerAdmin;
use SonataAdminBundleAdminAdmin;
use SonataAdminBundleDatagridListMapper;
use SonataAdminBundleDatagridDatagridMapper;
use SonataAdminBundleFormFormMapper;
class GroupeAdmin extends Admin
{
    protected function configureListFields(ListMapper $listMapper)
    {
        $listMapper
            ->addIdentifier('id')
            ->addIdentifier('name')
            ->add('country');
    }
    protected function configureFormFields(FormMapper $form)
    {
        $form
            ->add('id', null, [
                'attr' => [
                    'readonly' => true,
                ],
            ])
            ->add('name')
            ->add('country');
    }
    protected function configureDatagridFilters(DatagridMapper $filter)
    {
        $filter
            ->add('id')
            ->add('name')
            ->add('country');
    }
}

实体和管理页面应彼此分开。您的实体不应扩展 Sonata 提供的 Admin 类,但您应该创建一个扩展 Admin 类的新文件。

sonata.admin.post:
    class: TicClasseBundleAdminAdminGroupe /*Locating the admin file*/
    tags:
        - { name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" }
    arguments:
        - ~
        - TicClasseBundleEntityGroupe
        - ~
    calls:
        - [ setTranslationDomain, [AcmeDemoBundle]]

我强烈建议(再次)阅读Sonata提供的文档,请参阅:https://sonata-project.org/bundles/admin/3-x/doc/getting_started/creating_an_admin.html

相关内容

  • 没有找到相关文章

最新更新