首页 \ 问答 \ 如何使用具有实体数组的实体来实现此symfony表单?(how to implement this symfony form, with a entity which has a array of entities?)

如何使用具有实体数组的实体来实现此symfony表单?(how to implement this symfony form, with a entity which has a array of entities?)

我有一个symfony形式的大问题。 我需要做以下事情:

我想为实体生成一个表单,但是这个实体还有一个其他实体的数组,这些实体也应该被添加(如果可能的话)。

这里是数据结构:我有一个名为Foo的实体(保存一个FooItems数组)和一个实体FooItems。

class Foo
{   
    {...}
    /**
     * @var string
     * @ORM\Column(type="string")
     */
    private $fooItems;
    {...}

现在我需要为此构建一个表单,用户可以向Foo添加一个或多个FooItem。 怎么实现这个?


i have a big problem with a symfony form. i need to do the following:

I want to generate a form for a entity, but this entity has a array of other entities which should be also added (if possible).

here is the data structure: I hava a Entity called Foo (keeps a array of FooItems) and the a entity FooItems.

class Foo
{   
    {...}
    /**
     * @var string
     * @ORM\Column(type="string")
     */
    private $fooItems;
    {...}

now i need to build a form for this, the user can add one or more FooItems to the Foo. How to realise this?


原文:https://stackoverflow.com/questions/13900422
更新时间:2021-12-27 14:12

最满意答案

在这个例子中,这个用例已经有一些代码。

providers: [{provide: TEST_VALUE, useValue: 'Just an example'}],

你可以用它来注入字符串Just an exampleLoginDialogComponent

在你必须按照以下方式初始化TEST_VALUE之前:

const TEST_VALUE = new OpaqueToken("test_value");

然后,您可以通过这种方式扩展组件构造函数以获取值:

constructor(@Inject(TEST_VALUE) private myValue: string) {}

要么

你也可以传递一个对象来代替字符串。 这看起来是这样的:

providers: [{provide: TEST_VALUE, useValue: <IMyDialogArgs>{
    foo: "foo",
    bar: 0
}}],

In the example there is already some code for this use-case.

providers: [{provide: TEST_VALUE, useValue: 'Just an example'}],

You can use this to inject the string Just an example into the construtor of LoginDialogComponent.

Before you have to initialize TEST_VALUE the following way:

const TEST_VALUE = new OpaqueToken("test_value");

Then you can extend your components constructor this way to get the value:

constructor(@Inject(TEST_VALUE) private myValue: string) {}

Or

Instead of a string you can also pass an object. This would look this way:

providers: [{provide: TEST_VALUE, useValue: <IMyDialogArgs>{
    foo: "foo",
    bar: 0
}}],

相关问答

更多
  • 这是目前报道的QtCreator错误: https://bugreports.qt-project.org/browse/QTCREATORBUG-10940?page=com.atlassian.streams.streams-jira-plugin:activity-stream-issue-tab https://bugreports.qt.io/browse /请见QTCREATORBUG-10940 所以不要担心警告,它会被修复 This is currently a reported QtCre ...
  • 你不能在你的情况下使用@Input,因为这需要一个你可以传递requireCaptcha值的元素。 目的是使用providers Array将值传递给对话框组件。 首先创建一个InjectionToken: export const REQUIERE_CAPTCHA = new InjectionToken('requireCaptcha'); 然后在你的showCustomDialog方法中使用: let pDialog = this.dialogService.showCustomD ...
  • 首先,我可能会错过一些东西,没有代码等等,但... 其次:也许你不应该使用dialoges? 看起来像一个繁琐的用户界面。 只需使用这些片段呢? 虽然你说你正在使用DialogFragments,所以也许你已经考虑过了,并将它们用作“常规”片段。 第三:当显示的片段被移除/隐藏时关闭对话框? 例如,在片段或更集中的地方使用onStop()回调,您可能会保存当前显示的片段并决定显示一个新的片段。 通过调用对话框中的对象或片段或关闭活动中的对话框来关闭对话框。 请参阅解除对话: http : //develop ...
  • 在这个例子中,这个用例已经有一些代码。 providers: [{provide: TEST_VALUE, useValue: 'Just an example'}], 你可以用它来注入字符串Just an example到LoginDialogComponent 。 在你必须按照以下方式初始化TEST_VALUE之前: const TEST_VALUE = new OpaqueToken("test_value"); 然后,您可以通过这种方式扩展组件构造函数以获取值: constructor(@Inje ...
  • 您可以选择使用累积对话框。 这只是一个普通的对话框,你可以在其中输入一个字符串: String info = "GPS: Connected\nWiFi: NOT Connected\n\nBattery: 45%"; (只是举个例子)。 这样,您可以使用\ n (新行)作为连接器将所有消息连接到一个字符串中(将其设置为双倍,以分隔不一致的信息 - 例如电池状态,在示例中)。 你会得到一个单一的信息面板 。 像(在例子中): GPS:已连接 WiFi:未连接 电池:45% You might opt fo ...
  • 使用 alert("on device ready!!!!"); 要么 navigator.notification.alert("PhoneGap is working"); Use alert("on device ready!!!!"); or navigator.notification.alert("PhoneGap is working");
  • 您应该将IP地址作为Connect类构造函数的参数传递。 然后,您可以查看FactoryModuleBuilder,以便可以在代码中为Connect类注入依赖项。 至于你对单身人士的要求,我不太清楚你的意思。 根据定义,单例意味着只有一个类的实例。 在这里,你想要两个(或可能更多)。 我怀疑的是,在整个应用程序中,每个IP字符串最多只需要一个Connect实例。 如果是这种情况,您的工厂需要比FactoryModuleBuilder自动创建的工厂更聪明一些。 它可以是一个单例本身,并存储一个索引(map?c ...
  • 要在Ionic Framework应用程序中使用本机警报,您需要首先安装Cordova对话框插件: cordova plugin add cordova-plugin-dialogs 该插件默认不包含在Ionic Framework中。 安装插件后,您可以使用警报对话框: navigator.notification.alert( "Feil brukernavn eller passord.", // the message function() {}, ...
  • JSON.stringify方法接受js对象并返回该对象的字符串化版本。 例如,如果将js对象{ name: 'shyju' }传递给此方法,您将获得字符串{"name":"shyju"} 当ajax调用是GET类型时,数据将作为查询字符串值发送。 $.ajax方法会根据需要将您在data属性中传递的js对象转换为querystring键值对并发送它。 所以基本上你当前的代码就像这样发送查询字符串 Home/SaveNewStagePlan?{"name":"shyju"}` 所以你可以清楚地看到这不是一 ...
  • 在尝试使用div之前,你必须将div附加到某个东西上。 喜欢 document.append('
    '); You have to append that div to something before trying to use it. Like document.append('
    ');

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)