Moving a php project to codeigniter or updating th

2019-06-23 08:28发布

问题:

I'm trying to figure out the best way to handle a php project going forward. It was built a few years ago on a custom framework - the framework wasnt strict MVC...it simply had controllers and views, and libraries.

I've since added in additional functionality and it's starting to feel very much like a complete mess, with old code and new code mixed up, and no decent database management.

I'm struggling to decide what my best option is. On the one hand, I could keep patching the existing codebase in the hope that I can make it somewhat more usable and futureproof, or move to codeigniter (note: I say codeigniter as I've got a fair amount of experience with it).

The Codeigniter option would obviously mean I'd have to go through everything, and there will no doubt be a fair amount of recoding, however in the long term it may be worth it.

There was another option I was considering, and that was the Laravel framework. I have no direct experience with it, however I hear that Laravel 4 (not released yet) is supposed to be excellent.

So, putting those three options on the table, which would you pick and why? I'm looking for a compelling reason to choose one over the other, as quite frankly I dont have a clue which route I'm best taking at the moment!

回答1:

Short answer: neither.

Now a bit longer version..

I get the impression, that you are confused about, which problems frameworks aim to solve. When you use a framework, what you gain is shorter development for simple applications. What you always loose is performance and, usually, maintainability.

Frameworks are made to provide you with tools for solving simple problems. Which means that there is a lot of thing's, that you do not need. And there is also problems, that frameworks do not solve or even actively hinder your efforts in making a solution.

What you should do instead..

Refactor your code.

If you have been working on the project for long time, you will have a lot of lessons, that you learned from this experience. Utilize them by improving the existing codebase.

  • if there are flaws in your architecture: restructure broken parts
  • if you are not sure, whether something works: add unittests
  • if something seems to be slow: profile you code and optimize
  • if you do not know what something does: find out and add comments

This way you will enhance both you project and your skills.

P.S
Even if you were starting new project, I would recommend to avoid both frameworks. They both are filled with bad practices and worse code: global state everywhere, procedural programming, misinterpretation of MVC, disregard for OOP principles and laws.



回答2:

I've actually had experience with this, as I recently moved an older site from what was essentially a modular Model-View setup to CodeIgniter (with the MX modular extension). It didn't take too long and easily the longest part of it was converting the models over to CodeIgniter's ActiveRecord paradigm.

It sounds like you don't even have any model conversion to do, so I'd say converting to CodeIgniter shouldn't be too much of a challenge, especially given your experience with it.



回答3:

There's no definite right or answer - there will have to be an investment made in time either now or spread out in the future.

Personally, I'd bite the bullet and go with migrating to CI. If you're fighting your code more than fixing it then the effort you put in the short term will be worth it in the long run.

Most of the time, it doesn't take much time to get an existing PHP application into CodeIgniter - you'll just have to spend more time re-organizing your code afterwards.



回答4:

Switch to Laravel and its already compatible to php v5.3+ with a great community. I did use CI for many projects but getting along with Laravel was one of my best decision. L3 is stable and doing perfectly well and L4 is going to redefine the use of php maximizing efficiency.

If you have your old system well structured in form of OOP standards then u can invest a little bit of time to migrate the usable potions to Laravel and also combine super features of Laravel to save lots of your time. For example Laravel uses well structured ORM called Eloquent and can snap in all your data models in just few minutes. If you also take a look at the active community you will be a happy man to get quick support.