奏鸣曲 缺少论点

Posted

技术标签:

【中文标题】奏鸣曲 缺少论点【英文标题】:Sonata Missing argument 【发布时间】:2014-02-04 14:14:53 【问题描述】:

当我尝试使用全新安装的奏鸣曲 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 Tic\ClasseBundle\Entity;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;
use Doctrine\ORM\Mapping as ORM;

/**
 * Groupe
 *
 * @ORM\Table()
 * @ORM\Entity(repositoryClass="Tic\ClasseBundle\Entity\GroupeRepository")
 */
class Groupe extends Admin

    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @var string
     *
     * @ORM\Column(name="groupe", type="string", length=255)
     */
    private $groupe;

    /**
     * @var string
     *
     * @ORM\Column(name="enseignant", type="string", length=255)
     */
    private $enseignant;

    /**
     * @var string
     *
     * @ORM\Column(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')
        ;
    

config.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:
        cs-s-rewrite: ~
        #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        

和 admin.yml

services:
    sonata.admin.post:
        class: Tic\ClasseBundle\Entity\Groupe
        tags:
            -  name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" 
        arguments:
            - ~
            - Tic\ClasseBundle\Entity\Groupe
            - ~
        calls:
            - [ setTranslationDomain, [AcmeDemoBundle]]

谢谢

【问题讨论】:

您必须将您的代码编辑成问题 我编辑我的第一个问题。 为什么你的实体类扩展Admin 为什么你的Entity类和Admin类混在一起?消息似乎也很清楚,您在 __construct() 方法中缺少一个参数。尝试检查您是否在 Service.yml 中正确注入了服务 【参考方案1】:

您的实体类 Groupe 不正确。

它不会扩展 Sonata 管理类。

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

例子:

<?php

namespace Tic\ClasseBundle\Controller\Admin;

use Sonata\AdminBundle\Admin\Admin;
use Sonata\AdminBundle\Datagrid\ListMapper;
use Sonata\AdminBundle\Datagrid\DatagridMapper;
use Sonata\AdminBundle\Form\FormMapper;

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

【讨论】:

【参考方案2】:

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

sonata.admin.post:
    class: Tic\ClasseBundle\Admin\AdminGroupe /*Locating the admin file*/
    tags:
        -  name: sonata.admin, manager_type: orm, group: "Gestion de classe", label: "Groupe" 
    arguments:
        - ~
        - Tic\ClasseBundle\Entity\Groupe
        - ~
    calls:
        - [ setTranslationDomain, [AcmeDemoBundle]]

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

【讨论】:

以上是关于奏鸣曲 缺少论点的主要内容,如果未能解决你的问题,请参考以下文章

在 symfony2 sonata 管理包中设置默认值

装完vivado以后一直运行不了。。。

ie解决缺少函数错误

天然气调用支付缺少参数怎么解决

调用支付jsapi 缺少参数appid

缺少 RapidAPI 应用程序密钥(不缺少)