dongxi4235 2018-01-28 20:14
浏览 53
已采纳

动态表单输入服务

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 :

Service one have three inputs first name, last name and avatar

service tow have four inputs name email sexe and phone number

..

..

So what is the best solution to store this information? mysql database or json file or xml file

  • 写回答

1条回答 默认 最新

  • dongsu4345 2018-01-28 20:54
    关注

    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.

    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/

    At any rate, no-one at stackoverflow knows what your data is to be used for. 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.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探