如何将旧的 OOP PHP 项目转换为 Yii 框架? [英] How do you convert an old OOP PHP project into the Yii Framework?

查看:22
本文介绍了如何将旧的 OOP PHP 项目转换为 Yii 框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经有一个可用的 OOP 网站.大多数 php 与 html 是分开的.我想知道是否有人有任何关于如何将该站点应用到 Yii 框架的提示.

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.

编辑

网站使用jquery、html、css、php、javascript.它还包含许多我从代码峡谷购买的库和类.像一个地理定位库,phpthumb(图像缩略图),喜欢和不喜欢的系统.如何将这些库导入 Yii?

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?

推荐答案

一年前我有一个类似的任务,但代码根本不是真正的面向对象.我创建了一个新的 Yii 项目并将旧站点作为该项目中的 lib 放置.然后我在 Yii 中设置基础知识,如数据库访问,无论两个项目中都需要哪个会话值等.然后我逐个路由,逐个特性地移植.花了一些时间,但效果非常好.我刚刚有一个引导脚本,它根据ported_routes"路由请求.

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".

当涉及到重用类时,如果它们结构良好且不依赖于旧代码,则应该不成问题.Yii 对这些东西没有任何限制,所以只需将它们添加为库或浏览 Yii 文档,看看将它们重构为 Yii 组件或子类是否有意义.

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.

至于从 skratch 重做的 CSS 和 JS,使用 LESS 和更新的 JS 库.自从编写原始代码以来,JS 世界发生了很多事情.Yii 也不要求您遵循任何预先确定的标记结构,因此理论上您应该能够使用旧的 CSS,除非您想更改标记基础.

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.

如果您的旧代码具有类似 MVC 的结构,则操作和视图的移植会更加顺畅,但无论如何,我认为您几乎都采用了类似的方法.

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.

这篇关于如何将旧的 OOP PHP 项目转换为 Yii 框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆