How do you convert an old OOP PHP project into the

2019-01-25 22:10发布

I already have a working OOP website. Most of the php is separated from the html. I was wondering if anyone had any tips on how to apply that site into the Yii Framework.

Edit

The website uses jquery, html, css, php, javascript. It also consists of a lot of libraries and classes I bought of code canyon. Like a geolocation library, phpthumb (image thumbnails), like and dislike system. How does one go about importing these libraries into Yii?

标签: php oop web yii
2条回答
三岁会撩人
2楼-- · 2019-01-25 22:51

I had a similar task a year ago, but the code wasn't really OO at all. I created a new Yii project and placed the old site as a lib in the that project. I then set up the basics in Yii like database access, whichever session values were needed in both projects etc. I then ported route by route, feature by feature. It took some time, but it worked out really well. I just had a bootstrap script which routed requests based on "ported_routes".

When it comes to reusing classes that should not be a problem if they are well structured without dependencies on the old code. Yii places no restrictions on that stuff, so just add them as libs or browse through the Yii docs and see if it makes sense to refactor them into Yii components or subclass something in there.

As for CSS and JS that was redone from skratch, using LESS and newer JS libs. A lot had happened in the JS world since the original code was written. Yii does not require you to follow any predetermined structure for markup either, so in theory you should be able to use the old CSS unless you want to change markup fundamentals.

If your old code has a MVC-like structure the porting of actions and views will go smoother, but regardless you are pretty much left with a similar approach I think.

查看更多
倾城 Initia
3楼-- · 2019-01-25 22:57

well there is no hard and fast convertor which will convert your site from traditional OOP model to Yii. You have to do all of it yourself. But you can opt to do it in stages though.

-at mathew commented I must clarify that you have to do it all by yourself and there is no easy way to convert your existing code to what Yii understands

查看更多
登录 后发表回答