当我尝试使用全新安装的sonata adminBUndle访问我的网站时出现此错误。我可以看到列表,我可以看到仪表板,但如果我尝试添加帖子,我收到此消息。
缺少Sonata \ AdminBundle \ Admin \ Admin :: __ construct()的参数1, 呼唤 第416行的C:\ wamp \ www \ sonata \ vendor \ sonata-project \ doctrine-orm-admin-bundle \ Sonata \ DoctrineORMAdminBundle \ Model \ ModelManager.php并在 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:
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
和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]]
thax
答案 0 :(得分:0)
您的实体类Groupe不正确。
它不会扩展Sonata管理类。
方法configureListFields
,configureFormFields
,configureDatagridFilters
不应该在这里。它们必须位于单独的管理类(模拟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');
}
}