简体   繁体   English

服务的动态表单输入

[英]Dynamic form inputs for services

I have a project with php 7 (laravel) where I have to create a registration form for different services,My client wants to create services dynamically and every service has different registration form for example : 我有一个使用php 7(laravel)的项目,我必须为不同的服务创建注册表单,我的客户希望动态创建服务,并且每个服务都有不同的注册表单,例如:

Service one have three inputs first name, last name and avatar 服务一具有三个输入,名字,姓氏和头像

service tow have four inputs name email sexe and phone number 服务拖车有四个输入名称,电子邮件sexe和电话号码

.. ..

.. ..

So what is the best solution to store this information? 那么,存储此信息的最佳解决方案是什么? mysql database or json file or xml file mysql数据库或json文件或xml文件

As for the storage, in this case a database is a natural choice as it handles concurrent access out of the box, while storing in a file would require some complications on your side. 对于存储,在这种情况下,数据库是一种自然的选择,因为它可以处理开箱即用的并发访问,而存储在文件中则需要一些复杂的操作。

But your real concern seems to be with the data structure, not the storage. 但是您真正关心的似乎是数据结构,而不是存储。 The challenge here is that different data providers provide different structures and you want them all in one structure. 这里的挑战是不同的数据提供者提供不同的结构,而您希望它们全部集中在一个结构中。

If service 1 provides first name and last name as separate fields, and service 2 sees them as a single field, the question is whether you make a single field (like in service 2) and concatenate values coming from service 1, or you make multiple name fields (like in service 1) and invent a method to separate values coming from service 2 into corresponding parts. 如果服务1将名字和姓氏作为单独的字段提供,并且服务2将它们视为单个字段,那么问题是您是创建单个字段(如在服务2中一样)并连接来自服务1的值,还是将多个命名字段(如服务1中的字段),并发明一种将服务2中的值分成相应部分的方法。

To make this decision wisely, you have to look how your data is to be used. 为了明智地做出此决定,您必须查看如何使用您的数据。 If you want a robot to send out emails starting with 'Dear Ms. Last Name' line, you will need to keep last name separately. 如果您希望机器人发送以“亲爱的女士姓氏”行开头的电子邮件,则需要单独保留姓氏。 If you have no such task in your planning horizon, you may wish to skip the dividing challenge and simply store all name fields in a single field. 如果您在计划范围内没有此类任务,则不妨跳过分案的挑战,只需将所有名称字段存储在一个字段中即可。

The problem of a correct data structure for folks' names is deeper than it seems. 人们姓名正确的数据结构问题比看起来要深。 Have a look at this nice post: http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ 看看这个不错的帖子: http : //www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/

At any rate, no-one at stackoverflow knows what your data is to be used for. 无论如何,stackoverflow上没有人知道您的数据将用于什么。 It is up to you to communicate to your client that they share this knowledge with you. 您有责任与您的客户交流,他们与您分享这些知识。 Then get some time to sit down and to sketch the structure that will suffice your immediate needs. 然后花一些时间坐下来,草绘满足您当前需求的结构。 Outline use cases, draw an ER diagram, put down on the paper some pseudocode to illustrate what data fields are needed by your system. 概述用例,绘制ER图,在纸上放一些伪代码,以说明您的系统需要哪些数据字段。

And most importantly, don't be afraid that it doesn't come out as good as you want. 最重要的是,不要害怕它的效果不如您想要的好。 The needs change over time, your understanding deepens, and it is only natural to constantly adapt your database structure and your code to the new reality. 需求随着时间的推移而变化,您的理解加深,并且不断地使数据库结构和代码适应新现实是很自然的。 It's okay. 没关系。 Come on, work it out. 来吧,解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM