Strategies for migrating a live site to an MVC framework?

There is a lot of good content about SO about MVC and about getting started with MVC, but it's hard for me to find anything about how best to implement the MVC framework on a pre-existing website.

My site is an unpleasant echo mishmash and concatenated HTML that will make any professional programmer, but it works.

I would like to spend some time solving the technical debt problem, but that means moving to a much more reasonable MVC structure.

If at all possible, I would like to avoid let 'er rip! 100% rewrite and run the approach, and instead take it at a time. But it seems that the basic centralized control room is not suitable for this approach?

+6
source share
3 answers

I agree with the other suggestions here, the framework will not be a magical fix.

however, this may help in the long run. I have now converted several mishmash sites to the kohana framework and had the following impressions.

initially I didn’t know very well kohan, so I found out that when transcoding mysite. I stopped rewriting and coded a whole new project from scratch to get to know kohana, and then went back to the rewriting project, now that I understood the structure better.

if you don’t understand the framework, it will be a steep learning curve, trying to use it to transform an old project

  • The first step in rewriting was to put all the business / database logic embedded in the pages at the top of each page (before html is released). So I did not change the flow / structure of the website, just separating the business logic from the display logic.

    After that I had a website that had easy-to-read business logic, only in the old structure, and at the same time I got acquainted with the old code base.

  • The next step I took was to fix any problems with the database structure so that everything was in 3rd normal form (if possible).

    it was easier for me to change the old code to a new database structure, and then to work and the old database structure in the new structure. (kohana is mainly based on agreements, not configuration, so it was nice to follow these agreements to facilitate long-term maintenance).

    having a good database structure makes life easier regardless of structure

  • The next step was to select a part of the website for replacement. set up routes in Cohan and let Kohan serve that part of the project. kohana (and other frameworks without a doubt) have a backup, if the file requested via url already exists on the site, then kohana will not process this request

    since you separated the business logic from the display logic in your php files, it is just a matter of separating the code into a controller and a view. make changes to both parts according to the frame. you can split the business logic into a model / controller after you have the controller / view working as expected

make your way through this part of the site to completion. then test / launch / bugfix etc.

then start again on the next part of the site.

in the end you will get there ...

although it took a long time to dub, it was useful to me, as sites are much easier to maintain now. (it is obvious that the gain will depend on the quality of the source code base)

luck

+5
source

If I understand what the general level of quality is for this code base, then there is no way to go to MVC in one step . It is simply not possible. Another bad news is that the framework will not help . They cannot magically turn a bad code base into something similar to the MVCish architecture.

Instead, you should focus on incremental refactoring. Your goal should be code that basically matches SOLID and LoD . And while you are reorganizing your code, architecture will arise on its own. MVC has many options and tastes.

A certain thing that you can pay attention to is how to use templates in php . Examine the code and see what you need to change according to your needs (this is more a direction, not a complete solution). And remember that in MVC-like structures, View is not a template, but View uses several templates.

Another thing you could win is to learn more about datamappers . Implementing them will be a good step towards creating a model layer.

Oh .. and then there are some general lectures that you could take a look at (all 30min +):

Oh, and this book contains some information about reorganizing large php projects. May be useful for you.

+6
source

can do. you can write your mod rewrites only to redirect to boot.php or something else if the actual file is not found at the requested path. this will allow you to do the partition at a time. making sure all your links are in order will be a nightmare.

you may need to rewrite and copy and paste the fragments that you will need from the old application when you go.

0
source

Source: https://habr.com/ru/post/899512/


All Articles