doujing5435 2013-04-02 02:29
浏览 54
已采纳

如何将JMVC(javascript-mvc)和服务器端MVC结合在一起

I have asked this quesion few days before here and no one answered it.
I had asked it in forum.javascriptMVC.com too and now I have a answer, however I need a a bit more idea.

Question:

I read javascriptMVC's documents and I loved it. 
But I don't know how to use it in a large scale project.

I think on the server-side a MVC framework is needed or can help so much. And I've worked with server side PHP frameworks.

I am confused, my understanding of JavascriptMVC projects is that they handle client side events on the browser capture events, execute AJAX requests, manage the responses/data from the server and also show them to user in a graphical interface.

I know that in PHP MVC projects we also have controllers (and actions) that any of them is a separate page with a single entry point, my point is that these pages are whole HTTP requests.

I think the combination of these two frameworks would be in a form of a single or few heavy files (including js , css , imgs etc) that loads and managed by another Javascript libary such as steal.js. Now user can work with site and its actions (as events) that result in running js functions that may change something in the UI or cause a AJAX request, as in Yahoo Mail where most things happens in one page.

So how will this affect the design of controllers and actions in PHP ? I mean normally in PHP MVC frameworks a lot of controllers and actions means a lot of pages. I think because of AJAX the number of controllers and actions should be actually less. I also think because of JMVC most controllers (and actions) should turn to AJAX responders, however how are layouts and views to be handled in this context?

Finally

  • I want to know about different aspects of using this method(JMVC+MVC). (I am using Yii as my server-side MVC framework and JavascriptMVC as my client-side MVC).
  • I also want to know about management of data on the client-side.
  • I would like to understand how AJAX and web-sockets could be used, where we can use AJAX and where we can use websockets?.
  • I want to understand about local-storage how we can use it for simulated page data management and maybe caching, how we can cache data coming from server as JSON in a form of a page? I am working on a very large project and I want to build its foundation very strong.
  • 写回答

3条回答 默认 最新

  • douyi1939 2013-04-08 06:18
    关注

    Say that you jave a JMVC framework where

    • The model gets data from the server using AJAX request - expecting JSON results.
    • The view does not rely on the server, for more that providing the raw HTML.
    • The Controllers do not rely on the server, for more that serving the JS files.

    Essentially you use the server what it "should" be used for, data storage and processing, while you let your client browser handle all the tedious stuff.

    Now, lets see how to define a server-side framework. As I see it we have several options, all of them fairly similar, albeit somewhat different (all returning someing in JSON format):

    • A fully fledged MVC such as cakePHP
    • Custom implementation
    • WebService implementation

    Personally I would use a WebService, and I already have. Or rather, I used a WebSocket based JSON-RPC WebService. Using a fully fledged MVC will have it's drawbacks in maintainability and, not insignificantly, server load. But it is very possible, just implement a view which formats the page as JSON...

    Making a JMVC client does not, in my view, mean that it cannot request new HTML from the server. But it does mean that that requested HTML should be free of data, other than meta-data the Java-View needs to know where to put data recieved from, for example, the WebService.

    So a main page in the JMVC could just contain a single

    <div id=content></div>
    

    and menu clicks can fetch a subpage from the server and load the content into content. Then that loaded content can contain some more javascript which starts WebService requests to get data from the server, to display in the empty placefolders it in turn contains.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 fluent的在模拟压强时使用希望得到一些建议
  • ¥15 STM32驱动继电器
  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退