How Do You Convert a Page-Based PHP Application to MVC?

后端 未结 11 769
野趣味
野趣味 2021-02-01 09:48

I\'ve been struggling for some time now with exactly how to recode a page-based PHP application using an MVC framework. Just for background, I am having to move the app into MVC

11条回答
  •  心在旅途
    2021-02-01 10:22

    Slightly off topic to your question... for the love of god don't forget your old URLS. The reason being is that the minute you flip the switch on the new site and its pretty URLS, all of the aggregated content held by the search engines will slowly expire, taking your SEO stats way down.

    UPDATE: If I try and stick with one controller per view...I will then be keeping code per request to a minimum, but is this the best way?

    If I understand you correctly, each controller would produce one page. This can be a really bad idea that I've experienced first hand in a maintenance position. If you have content that doesn't really match well to the OO paradigms then put it into a category: press releases, one offs, informational, etc and stick those into a controller that serves just those views or better yet a number of controllers per category to leave more fine grained control.

    The "MVC" framework I dealt with that did the one controller to view quickly became a convoluted mess with lots of hacks and spaghetti code.

    I have about 12 form pages that are used to create a "plan".

    I've had to do something similar and as goofy as it seems, having a "planningform" controller is probably best. Yes there are multiple tables to feed, but you can do simple stuff like $_SESSION['plannerController']['subject|action'][key][value] to keep each part of the form overall in check. Having each method handle part of the multi-page form can also be a benefit ( ex. What if your boss says they only need 6 out of the 12 pages or what if part 7 becomes really complicated and needs stuff like autocompletion ajax ).

    grouping mechanism not necessarily using it because they have something related with each other.

    I generally like the one class, one purpose paradigm but sometimes it just doesn't make sense to try and do that. There are cases where its clear cut, right out of the text book OO and other times the academic BS can go to hell. Your going to find stuff that doesn't fit the OO mold, so you can take a step back and try to merge things into common categories.

提交回复
热议问题