简体   繁体   English

MVC:将C ++模型插入基于Web的视图

[英]MVC: Plugging a C++ Model into a Web-based View

Background 背景

I am writing a tool using MVC where the model is written in C++, controller in JavaScript/jQuery and the view in HTML/CSS. 我正在使用MVC编写工具,其中模型是用C ++编写的,控制器是用JavaScript / jQuery编写的,视图是用HTML / CSS编写的。 The reason the model is in C++ is for eventual portability to a thick client from the "speed build" on web. 该模型使用C ++的原因是为了最终从Web上的“速度构建”将其移植到胖客户端。

Issue 问题

My major roadblock at this point is connecting my C++ model to the HTML form that is currently collecting input data from the user. 此时,我的主要障碍是将C ++模型连接到当前正在从用户收集输入数据的HTML表单中。

I have looked into Emscripten for compiling the C++ directly into JavaScript, but I don't like the idea of having my underlying model be visible to the end user in any form . 我已经研究过Emscripten ,可以将C ++直接编译为JavaScript,但是我不喜欢让我的底层模型以任何形式对最终用户可见的想法。 This is due to the model being hooked up to a MySQL server handling a lot of sensitive data. 这是由于该模型已连接到处理大量敏感数据的MySQL服务器。 I want to minimize risk of the end user accidentally (or purposely) messing with the function call invoking the model. 我想最大程度地降低最终用户意外(或故意)弄乱调用模型的函数调用的风险。

I have done quite a bit of research on PHP/C++ linking, but all the resources I could find have been severely outdated and/or convoluted. 我已经对PHP / C ++链接做了很多研究,但是我发现的所有资源都已经严重过时和/或令人费解。

I'd ideally like to have the the data pushed to the server using a POST method before invoking the model so I can have maximum control over input validation both on the end user and server side. 理想情况下,我希望在调用模型之前使用POST方法将数据推送到服务器,以便在最终用户和服务器端都可以最大程度地控制输入验证。

I've also thought about using PHP to push to the MySQL server then having the C++ pull down from the server, but this seems a little obfuscated and raises the issue of when/how to wake the C++ up. 我还考虑过使用PHP推送到MySQL服务器,然后将C ++从服务器中拉出,但这似乎有点令人困惑,并引发了何时/如何唤醒C ++的问题。

Question

Is there a good way to maintain security of my model (have it run entirely server-side behind a POST method) as well as the understandability of how this was implemented? 有没有很好的方法来维护我的模型的安全性(它已完全在POST方法后在服务器端运行)以及如何实现该模型? I am a temp employee and my project will pass to other hands for the port to a thick client from web. 我是临时工,我的项目将移交给其他人,以从Web移植到胖客户端。

Speed is also a concern, but I'm assuming (or hoping) that the only bottleneck will be the pipe/script between the POST to the server and the C++ since most of the heavy-lifting will be occurring in the model. 速度也是一个问题,但是我假设(或希望)唯一的瓶颈将是到服务器的POST和C ++之间的管道/脚本,因为大多数繁重的工作都会在模型中发生。

What about not putting any business logic in your model and instead break the model up into an Entity and Service ? 不将任何业务逻辑放入模型中,而是将模型分解为EntityService怎么办?

You could then use emscripten on the Entity while your Service holds all of your MySql connection logic. 然后,当Service包含所有MySql连接逻辑时,您可以在Entity上使用emscripten

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

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