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

后端 未结 11 760
野趣味
野趣味 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:15

    Assuming you have some sort of tests at hand, covering most (all?) of the functionality of your application.

    1. Flesh out a really basic structure of how your C-part will look like.
    2. Implement this structure ignoring the M and V, more or less just copying snippets of code from your page oriented files into your controllers
    3. Test that everything is still working as expected
    4. Go through every controller, extract an "M" and a "V". The "M" might be just an Active Record (I know, that's not a real model) or a row table gateway or something which is pretty fast to implement. The controller should now become thinner and thinner
    5. Test that everything is still working as expected
    6. Now that you know everything about your application, refactor again to extract a domain model if applicable. In some cases, this might just be a waste of time (CRUD-only/-intensive applications)
    7. Test that everything is still working as expected.

提交回复
热议问题