- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我的其中一份表格有问题。我有一个链接到其他 3 个文档的“资源”文档:
这是我的文档的定义:
class Resource {
/**
* @MongoDB\Id
*/
private $id;
/**
* @MongoDB\String
*/
private $name;
/**
* @MongoDB\String
*/
private $description;
/**
* @MongoDB\ReferenceMany(targetDocument="Tag")
*/
protected $tags;
/**
* @MongoDB\ReferenceOne(targetDocument="Category")
*/
private $category;
/**
* @MongoDB\ReferenceOne(targetDocument="DataRepository")
*/
private $dataRepository;
/**
* @MongoDB\file
*/
private $logo;
/**
* @MongoDB\Boolean
*/
private $available;
这是我的“资源”文档的 formType:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name');
$builder->add('description');
$builder->add('logo', 'file');
$builder->add('available', 'checkbox');
$builder->add('category', 'document', array(
'class' => 'AppBundle:Category'
));
$builder->add('tags', 'document', array(
'class' => 'AppBundle:Tag',
'multiple' => 'true'
));
$builder->add('dataRepository', "document", array(
'class' => 'PortailCatalogBundle:DataRepository'
));
}
生成的表单是完美的,但是当我提交它时,它似乎并没有像异常(exception)那样滋润我的实体。这是请求:
["request"]=>
object(Symfony\Component\HttpFoundation\ParameterBag)#7 (1) {
["parameters":protected]=>
array(1) {
["resource"]=>
array(7) {
["name"]=>
string(14) "Ressource N°1"
["description"]=>
string(28) "Juste un test parmi d'autres"
["available"]=>
string(1) "1"
["category"]=>
string(24) "551c02b5a246cb287c09bcde"
["tags"]=>
array(2) {
[0]=>
string(24) "551c02b5a246cb287c09bcdc"
[1]=>
string(24) "551d0ac2a246cbe40809bc97"
}
["dataRepository"]=>
string(24) "551d650aa246cb700e09bc9d"
["_token"]=>
string(40) "4adfcc295b2305c784347311d3bbad55c260c6ed"
}
}
}
所有这些 objectId 都是正确的,但是在提交时,表单会为这 3 个文档生成错误,错误为“此值无效。”
我发现查询是在提交表单后立即完成的:
db.category.find({ "_id": ObjectId("551e66a2a246cba51909bc9c") });
db.tag.find({ "_id": ObjectId("551e66a2a246cba51909bc9d") });
db.dataRepository.find({ "_id": ObjectId("551e66a2a246cba51909bc9e") });
如您所见,objectId 不匹配。我觉得我搞砸了 formType 定义部分。
我没有在 DoctrineMongoDBBundle 中找到任何关于这种形式的文档......任何想法或文档链接?
谢谢。
最佳答案
我的源代码没有任何错误。我对 doctrine/doctrine-odm 包进行了 Composer 更新,表格按预期工作(显然添加了包的提交)。
关于php - Symfony2 和 MongoDB : FormType of a document with references,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29487245/
在Symfony中创建自定义字段时,有一种方法定义了 getParent 我们通过从 AbstractType 类扩展,然后使用 getParent 方法返回父类型来定义我们的类。而不是从父类扩展。
我有一个扩展 AbstractType 的 PostType 表单。在 Controller 中,如果满足某些条件,我想为其添加一个字段。我可以以某种方式执行此操作,还是有其他修改 Controlle
在 Symfony 2.8 中,在自定义表单类型中,是否可以让 setAllowedValues 返回取决于另一个选项的值的结果?没有明显的方法可以访问 Options据我所知,闭包中的对象。 pub
我在 nameType.php 中声明了一个表单, View 呈现所有字段,但我想手动添加另一个字段。 表格: {{ form_widget(form) }} 并获取 Co
我在 Symfony3 中有一个表单,我按照文档初始化它,如下所示: $form=$this->createForm(BookingType::class,$booking); $booking 是一
我有一个带有 1 个 EntityType 字段的表单,该字段必须包含取决于第二个 EntityType 字段的选项,该字段未映射到第一个实体中,如下所示: 服务类型.php : public fun
如何更改 symfony2 formType 类中的默认文本字段大小 最佳答案 你有没有尝试过: $builder->add('your_text_field', 'text', array(
我尝试从由 AbstractType 扩展的 FormType 访问服务。我怎样才能做到这一点? 谢谢! 最佳答案 作为基于先前答案/评论的完整答案: 为了从您的表单类型访问服务,您必须: 1) De
我想从用户那里选择一种问卷类型,所以我设置了一个包含问卷类型的选择。 类型是从实体 QuestionType 加载的。 $builder ->add('questionType',
初看: 我已经用实体制作了这个数据库结构,而不是转储和可视化。 从 phpMyAdmin 添加内容到数据库或显示代码中的数据没有问题,但是当我尝试使用 formtype 构建表单时,例如: 主要形式是
我正在尝试从 FormType 中的当前路由访问参数 page。它适用于 Controller,但不适用于 FormType。我想避免传递像 /?page=1 这样的参数,而更喜欢 /page/1。
我的 Symfony2 FormType 中有一个 onPreSubmit。 public function onPreSubmit(FormEvent $event) { $data = $
我对 Symfony FormType 测试有疑问。 http://symfony.com/doc/current/cookbook/form/unit_testing.html 在我的表单类型中,e
我面临的问题是我必须在包含所有父实体(类别实体)的表单中创建一个选择框。现在我设法做到了: $builder->add('parent', 'entity', array(
我创建了一个这样的自定义表单类型: class PositioningFlashType extends AbstractType {
我正在尝试找到一个最可重用的工作选项,以便能够从 FormType 进行翻译。 我的第一个选择是通过这种方式专门为每个 FormType 声明一个服务: 服务.yml form.enquiry:
我想添加字段 country (字符串) 到我的 Form\Type . country与Entity\Country无关, 并且应该存储国家代码(en, it, fr, ...) 而不是实体的 ID
我在 Symfony 2.8 中遇到了这个问题:我无法通过将查询传递给表单选项来呈现自定义变量。 请参阅下面的代码,我已经尝试过: 这是我的 Controller : $form = $this->c
我正在接受培训,但我在 symfony 3 下 我遇到了这个错误 Expected argument of type "string", "Test\FrontBundle\Form\Type\She
我有一个用户编辑表单,我想在其中管理分配给用户的角色。 目前我有一个多选列表,但我无法使用 security.yml 中定义的角色层次结构填充它。 是否有某种方法可以将此信息传递给 FormType
我是一名优秀的程序员,十分优秀!