Symfony2嵌入表单值(Symfony2 Embed form values)

我有自己的实用程序CalculatorType,用于计算我的文档的值(我正在使用ODM),而不是对另一个文档或子数组|对象的引用。 它有简单的2输入:

 $builder
            ->add('price', 'text', array(
                'label' => false,
                'data' => isset($options['data']) ? $options['data']->getPrice() : '0.00'
            ))
            ->add('count', 'integer', array(
                'label' => false,
                'data' => isset($options['data']) ? $options['data']->getCount() : '10000'
            ));

在父母形式我有:

$builder->
 ... // multiple fields
 ->add('calculator', 'calculator');

因此,当我尝试保存表单时,出现错误:

Neither the property "calculator" nor one of the methods

要跳过设置计算器字段,我已将mapped => false添加到选项中

 ->add('calculator', 'calculator', array('mapped' => false));

并添加了eventlistener来转换计算器数据

    $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
        $data = $event->getData();
        $data["price"] = $data["calculator"]["price"];
        $data["count"] = $data["calculator"]["count"];
        unset($data["calculator"]);
        $event->setData($data);
    });

现在表单提交值但计算器字段没有传递给嵌入表单,因为未设置$ data ['calculator']

如果我评论未unset($data["calculator"]); 然后我有一个错误

This form should not contain extra fields 

所以我找不到任何方法让这个表格起作用。 有任何想法吗?


I have my own utility CalculatorType for just calculating values for my document(I am using ODM), not reference for another document or sub arrays|object. It has simple 2 inputs:

 $builder
            ->add('price', 'text', array(
                'label' => false,
                'data' => isset($options['data']) ? $options['data']->getPrice() : '0.00'
            ))
            ->add('count', 'integer', array(
                'label' => false,
                'data' => isset($options['data']) ? $options['data']->getCount() : '10000'
            ));

In parent form I have:

$builder->
 ... // multiple fields
 ->add('calculator', 'calculator');

So when I am trying to save my form, I have an error:

Neither the property "calculator" nor one of the methods

To skip setting calculator field, I've added mapped => false to options

 ->add('calculator', 'calculator', array('mapped' => false));

and added eventlistener to transform calculator data

    $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
        $data = $event->getData();
        $data["price"] = $data["calculator"]["price"];
        $data["count"] = $data["calculator"]["count"];
        unset($data["calculator"]);
        $event->setData($data);
    });

Now form submits values but calculator fields not passing to embed form, because of unsetting $data['calculator']

If I comment unset($data["calculator"]); then I have an error

This form should not contain extra fields 

So I can't find any way to make this form work. Any ideas?


原文:https://stackoverflow.com/questions/22757366
2022-06-04 10:06

满意答案

您可以考虑客户端身份验证流程或使用带有OAuth对话框的 JS-SDK ,这样您可以轻松避免指定redirect_uri因为它可能由JS-SDK自动提供(或者您可以使用当前URL window.location ,如客户端文档中所示)侧认证流程)。

笔记:

虽然这可以帮助你避免使用redirect_uri实际问题更深一点......

redirect_uri使用将使这种流程难以实现,不仅因为无法预测它,而且由于要求redirect_uri应该位于App Domain中 ,因此使用JS-SDK也是如此。

应用设置截图

因此,通常您需要在应用程序设置中放置redirect_uri / URL应用程序运行的域名,这在许多客户端/域的情况下是令人讨厌的。

您可以通过使用单独的(可公开访问的)主机来实现身份验证流程,但在执行此操作之前,最好先问自己几个问题:

  1. 谁将对该主机负责,如果该主机出现问题,所有客户将会遇到什么情况。
    • 这是额外的依赖,最好避免。
  2. 您是否会在应用程序设置中为所有客户提供域名?
    • 这可能导致违反向第三方传输数据的平台政策(在此之前咨询公司律师)
  3. 您是否需要为所有客户使用单一应用程序?
    • 如果不是,您最好指示客户端设置应用程序并使用他们获得的凭据配置您的应用程序/代码。

总结一下:
您可以为每个客户端创建单独的应用程序,或指示客户端将应用程序设置为应用程序的安装/设置过程的一部分。 稍后您可以使用客户端身份验证流程来创建适用于每个客户端的通用代码(这也适用于服务器端流程,但需要一些额外的工作,并且使用JS-SDK FB.login它可能是一个插入功能没有任何额外的工作)。


You may consider Client Side authentication flow or using JS-SDK with OAuth Dialog, that way you may easily avoid specifying redirect_uri since it may be provided automatically by JS-SDK (or you may use current URL window.location as shown in documentatio of Client Side auth flow).

Notes:

While this may help you to avoid usage of redirect_uri actual problem is a bit deeper...

Usage of redirect_uri will make such flow hard to implement not only due to inability to predict it, but due to requirement that redirect_uri should be located within App Domain, same goes for usage of JS-SDK.

Application Settings screenshot

So generally you will be required to place the domain name of redirect_uri / URL Application Running on in the application settings, which is nasty in case of many clients/domains.

You may implement auth flow by using separate (publicly accessible) host but it's good to ask yourself a couple of question before doing so:

  1. Who will be responsible for that host and what will happen with all your clients if something going wrong with that host for auth only.
    • It's additional dependency which is better to avoid.
  2. Will you be albe to provide domains for all of your clients in application settings?
    • This may lead to violation of platform policies on data transfer to third parties (consult a company lawyer before doing so)
  3. Are you required to use single Application for all your clients?
    • If not you better instruct clients to set-up application and configure your application/code with credentials they got.

Summarizing stuff:
You can create separate application for every client or instruct client to set-up application as part of install/set-up process for you application. Later you may use Client Side authentication flow to create generic code that will work for every client (this is possible with Server Side flow too, but will require some additional work and with JS-SDK FB.login it may be a drop-in functionality without any additional work).

相关问答

更多

将IdentityServer3与独立的EXE结合使用(不使用'redirect_uri'?)(Using IdentityServer3 with a standalone EXE (without using 'redirect_uri'?))

您可以像Kirk Larkin所说的那样做 - 使用客户端凭证流程。 以下代码在.NET中: var client = new TokenClient( BaseAddress + "/connect/token", "clientId", "clientSecret"); var result = client.RequestClientCredentialsAsync(scope: "my.api").Result; ...

使用PHP的Shopify API,redirect_uri和应用程序url必须具有myshopify.com的匹配主机?(Shopify API using PHP, redirect_uri and app url must have matching hosts of myshopify.com?)

您收到的错误告诉您,您在合作伙伴仪表板中为应用程序输入的应用程序URL的域与您在OAuth请求中提供的域不同。 确保它被列为本地主机,并且错误应该消失。 The error you're receiving is telling you that the domain of the application URL you entered for the app in the Partners dashboard differs from the one you're providing with ...

错误:redirect_uri_mismatch :: redirect_uri必须匹配注册的回调URL(error : redirect_uri_mismatch :: The redirect_uri MUST match the registered callback URL)

您的回叫网址不正确 - 它应该是http:// localhost:5000 / login / github / authorized Flask-Dance的文档表示,代码创建了一个带有两个视图“/ github”和“/ github / authorized”的蓝图“github”。 蓝图还配置了“/ login”的url_prefix,因此您的回调URL必须为http:// localhost:5000 / login / github / authorized 。 这段代码制定了一个蓝图...

当redirect_uri不适用时,是否有一个OpenID Connect授权类型或机制供应用程序轮询auth-code?(Is there an OpenID Connect grant type or mechanism for an app to poll for the auth-code when redirect_uri doesn't apply?)

它存在且名称为“无浏览器和输入约束设备的OAuth 2.0设备流程”,但尚未完全标准化,请参阅: https ://tools.ietf.org/html/draft-ietf-oauth-device-flow Google还以特定于供应商的方式实施了此流程avant-la-lettre: https : //developers.google.com/identity/protocols/OAuth2ForDevices It exists and has a name, "OAuth 2.0...

错误消息:redirect_uri不属于应用程序(Error Message: redirect_uri is not owned by the application)

无论是页面标签还是画布,您都必须在https://developers.facebook.com/apps中标识网站的网址 我如何修复: 应用领域:megalopes.com(域名) 网站网址:/安全画布网址:/安全页面标签网址: https : //www.megalopes.com (子域名) Regardless of being page tab or canvas, you must identify the website Site URL in https://developers....

Facebook - 错误消息:redirect_uri不属于应用程序(Facebook - Error Message: redirect_uri is not owned by the application)

填写选项卡设置中的App Domain:和Site URL:字段。 这将有助于解决您的问题。 您必须确定重定向网址与您指定的网域相符。 Populate the App Domain: and Site URL: fields in the Tab Settings. That will help with your problem. And you have to be sure that the Redirect URL matches the domain you specify.

redirect_uri阻止使基于Intranet的应用程序的能力(redirect_uri blocking ability to make intranet-based application)

您可以考虑客户端身份验证流程或使用带有OAuth对话框的 JS-SDK ,这样您可以轻松避免指定redirect_uri因为它可能由JS-SDK自动提供(或者您可以使用当前URL window.location ,如客户端文档中所示)侧认证流程)。 笔记: 虽然这可以帮助你避免使用redirect_uri实际问题更深一点...... redirect_uri使用将使这种流程难以实现,不仅因为无法预测它,而且由于要求redirect_uri应该位于App Domain中 ,因此使用JS-SDK也是如...

Facebook登录手机错误:redirect_uri不归应用程序所有(Facebook Login Mobile error: redirect_uri is not owned by the application)

在您的应用程序/设置下的https://developers.facebook.com/上 ,验证您所使用的网址是否与您正在使用的重定向网址相匹配。 移动实例是否从不同的URL运行? 如果这没有用,请包含您的代码。 On https://developers.facebook.com/ under your app/settings verify that the url you have matches the redirect url you are using. Is the mobile ...

LoginViewController:“客户端应用程序的配置redirect_uri无效”(LoginViewController: “The configured redirect_uri of the client application is invalid”)

所以看起来在重定向URI中有数字会导致它无效。 So it appears that having numbers in the redirect URI causes it to be invalid.

Facebook Canvas:redirect_uri不归应用程序所有(Facebook Canvas: redirect_uri is not owned by the application)

您需要在“canvas url”中放置的URL可能是localhost:8080(应用程序URL由“名称空间”决定,并且始终为http://apps.facebook.com/namespace (这必须是唯一的你的应用。) 您需要为http://developers.facebook.com/docs/reference/dialogs/feed/指定重定向URI <script> FB.init({appId: "YOUR_APP_ID", status: true, cookie: t...

相关文章

更多

Symfony2网站开发

http://blog.csdn.net/liubei5/article/details/132902 ...

HTML5 智能form表单新属性

内容摘要:HTML5 智能form表单新属性,主要包括智能表单介绍和智能表单使用与规范。但在不同支持H ...

关于一个页面多个form问题????????

当前我的页面是用一个&lt;c:forEach &gt;遍历出来的。有多个form每个都不一样,我可以 ...

form中如何接收传入的值

如题,怎么给form的一个hidden隐藏域中传个id进去 问题补充:不能存在那里面 ...

如何把复选框中的值传到form里?

&lt;td&gt; &lt;input type=&quot;checkbox&quot; nam ...

form load 的问题

baseinfoForm.form.load({ url: '/Url/Institution/In ...

获得表单里的值

请问大家 我一个页面有两个表单,怎么获得其中一个表单里的所有输入框里的值? 问题补充: ...

ext里window里放form的布局?

window里布局了一个form,window有个最大化按钮,点击最大化,form的布局就占windo ...

我是如何在15天开发出一个网站的

最近历经半个月开发了一个新的网站 湖南英才网 ,这是我个人开发的第N个独立网站了,不过和往常不同的是, ...

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本