gpt4 book ai didi

symfony - 没有与上下文相关的主要类别 : default

转载 作者:行者123 更新时间:2023-12-04 12:49:54 34 4
gpt4 key购买 nike

我想在我的管理类中添加个人资料图片,但出现此错误:没有context相关的主类:default我搜索了很多但没有解决方案。这是我的代码config.yml

# app/config/config.yml

sonata_media:
class:
media: Application\Sonata\MediaBundle\Entity\Media
gallery: Application\Sonata\MediaBundle\Entity\Gallery
gallery_has_media: Application\Sonata\MediaBundle\Entity\GalleryHasMedia
category: Application\Sonata\ClassificationBundle\Entity\Category

default_context: default # you need to set a context
db_driver: doctrine_orm # or doctrine_mongodb, doctrine_phpcr it is mandatory to choose one here
contexts:
default:
providers:
- sonata.media.provider.dailymotion
- sonata.media.provider.youtube
- sonata.media.provider.image
- sonata.media.provider.file
- sonata.media.provider.vimeo

formats:
small: { width: 100 , quality: 70}
big: { width: 500 , quality: 70}
# other contexts here
engine:
providers:
- sonata.media.provider.image

formats:
preview: { width: 100, quality: 100}
small: { width: 200, quality: 100}
large: { width: 600, quality: 100}
cdn:
server:
path: /uploads/media # http://media.sonata-project.org/

filesystem:
local:
directory: "%kernel.root_dir%/../web/uploads/media"
create: false
providers:
image:
service: sonata.media.provider.image
resizer: sonata.media.resizer.square # sonata.media.resizer.square
filesystem: sonata.media.filesystem.local
cdn: sonata.media.cdn.server
generator: sonata.media.generator.default
thumbnail: sonata.media.thumbnail.format
allowed_extensions: ['jpg', 'png', 'jpeg']
allowed_mime_types: ['image/pjpeg', 'image/jpeg', 'image/png', 'image/x-png']
file:
service: sonata.media.provider.file
resizer: false
filesystem: sonata.media.filesystem.local
cdn: sonata.media.cdn.server
generator: sonata.media.generator.default
thumbnail: sonata.media.thumbnail.format
allowed_extensions: ['pdf', 'txt', 'rtf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'odt', 'odg', 'odp', 'ods', 'odc', 'odf', 'odb', 'csv', 'xml', 'sql']
allowed_mime_types: ['text/csv','application/pdf', 'application/x-pdf', 'application/rtf', 'application/octet-stream', 'text/html', 'text/rtf','application/sql', 'text/plain','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-excel','application/x-iwork-numbers-sffnumbers','application/vnd.apple.numbers']

doctrine:
orm:
entity_managers:
default:
mappings:
FOSUserBundle: ~
SonataMediaBundle: ~
dbal:
types: #this is about this line and line below
json: \Doctrine\DBAL\Types\StringType

用户管理员

/**
* @param \Sonata\AdminBundle\Form\FormMapper $formMapper
*
* @return void
*/
protected function configureFormFields(FormMapper $formMapper)
{
$formMapper
->with('General')
->add('username')
->add('email')
->add('enabled')
->add('firstname')
->add('lastname')
->add('plainPassword', 'password', array(
'required' => (!$this->getSubject() || is_null($this->getSubject()->getId())),
))
->add('media', 'sonata_media_type',
array(
'provider' => 'sonata.media.provider.image',
'context' => 'default',
//'data_class' => 'Application\Sonata\MediaBundle\Entity\Media',
'required' => false)
)
->end();
}

用户实体

class User extends BaseUser
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;


/**
* @var
*
* @ORM\Column(name="firstname", type="string")
*/
protected $firstname;


/**
* @var
*
* @ORM\Column(name="lastname", type="string")
*/
protected $lastname;

/**
* @var \Application\Sonata\MediaBundle\Entity\Media
* @ORM\ManyToOne(targetEntity="Application\Sonata\MediaBundle\Entity\Media", cascade={"persist"}, fetch="LAZY")
*/
protected $media;

/**
* Set media
*
* @param \Application\Sonata\MediaBundle\Entity\Media $media
* @return User
*/
public function setMedia(\Application\Sonata\MediaBundle\Entity\Media $media = null)
{
$this->media = $media;

return $this;
}

/**
* Get media
*
* @return \Application\Sonata\MediaBundle\Entity\Media
*/
public function getMedia()
{
return $this->media;
}

/**
* Get id
*
* @return int
*/
public function getId()
{
return $this->id;
}

/**
* @return String
*/
public function getFirstname()
{
return $this->firstname;
}

/**
* @param String $firstname
*/
public function setFirstname($firstname)
{
$this->firstname = $firstname;
}

/**
* @return String
*/
public function getLastname()
{
return $this->lastname;
}

/**
* @param String $lastname
*/
public function setLastname($lastname)
{
$this->lastname = $lastname;
}
}

有什么帮助吗?对不起英语。

最佳答案

在 Github 页面上有 an issue where a contributor suggests运行此命令:

php 应用程序/控制台 sonata:classification:fix-context

出现此错误的原因是您尝试在上下文 default 下添加媒体,但上下文与类别无关(链接)。

关于symfony - 没有与上下文相关的主要类别 : default,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40505233/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com