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 errorThis 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
满意答案
您可以考虑客户端身份验证流程或使用带有OAuth对话框的 JS-SDK ,这样您可以轻松避免指定
redirect_uri
因为它可能由JS-SDK自动提供(或者您可以使用当前URLwindow.location
,如客户端文档中所示)侧认证流程)。笔记:
虽然这可以帮助你避免使用
redirect_uri
实际问题更深一点......
redirect_uri
使用将使这种流程难以实现,不仅因为无法预测它,而且由于要求redirect_uri
应该位于App Domain中 ,因此使用JS-SDK也是如此。因此,通常您需要在应用程序设置中放置
redirect_uri
/ URL应用程序运行的域名,这在许多客户端/域的情况下是令人讨厌的。您可以通过使用单独的(可公开访问的)主机来实现身份验证流程,但在执行此操作之前,最好先问自己几个问题:
- 谁将对该主机负责,如果该主机出现问题,所有客户将会遇到什么情况。
- 这是额外的依赖,最好避免。
- 您是否会在应用程序设置中为所有客户提供域名?
- 这可能导致违反向第三方传输数据的平台政策(在此之前咨询公司律师)
- 您是否需要为所有客户使用单一应用程序?
- 如果不是,您最好指示客户端设置应用程序并使用他们获得的凭据配置您的应用程序/代码。
总结一下:
您可以为每个客户端创建单独的应用程序,或指示客户端将应用程序设置为应用程序的安装/设置过程的一部分。 稍后您可以使用客户端身份验证流程来创建适用于每个客户端的通用代码(这也适用于服务器端流程,但需要一些额外的工作,并且使用JS-SDKFB.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 URLwindow.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 thatredirect_uri
should be located within App Domain, same goes for usage of JS-SDK.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:
- 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.
- 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)
- 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-SDKFB.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'?))
使用PHP的Shopify API,redirect_uri和应用程序url必须具有myshopify.com的匹配主机?(Shopify API using PHP, redirect_uri and app url must have matching hosts of myshopify.com?)
错误:redirect_uri_mismatch :: redirect_uri必须匹配注册的回调URL(error : redirect_uri_mismatch :: The redirect_uri MUST match the registered callback URL)
当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?)
错误消息:redirect_uri不属于应用程序(Error Message: redirect_uri is not owned by the application)
Facebook - 错误消息:redirect_uri不属于应用程序(Facebook - Error Message: redirect_uri is not owned by the application)
redirect_uri阻止使基于Intranet的应用程序的能力(redirect_uri blocking ability to make intranet-based application)
Facebook登录手机错误:redirect_uri不归应用程序所有(Facebook Login Mobile error: redirect_uri is not owned by the application)
LoginViewController:“客户端应用程序的配置redirect_uri无效”(LoginViewController: “The configured redirect_uri of the client application is invalid”)
Facebook Canvas:redirect_uri不归应用程序所有(Facebook Canvas: redirect_uri is not owned by the application)
相关文章
更多Symfony2网站开发
HTML5 智能form表单新属性
关于一个页面多个form问题????????
form中如何接收传入的值
如何把复选框中的值传到form里?
form load 的问题
获得表单里的值
ext里window里放form的布局?
INSERT INTO blog_appitem (user_id,appid,app_secret,is_valid) VALUES (1, 'wxf415741de036114c','48e1e345fd5f11c93af18ff1714c7f78',1)
我是如何在15天开发出一个网站的
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!