Welcome Guest, Not a member yet? Register   Sign In
Modular refactoring possible?
#1

[eluser]Tom Vogt[/eluser]
I'm running an old-school PHP application that consists of about 65,000 LOC with a lot of database stuff going on.

One of my devs has proposed moving to Zend Framework. I've wanted to move to CI a while ago, but decided that with available ressources, a refactoring effort would not be manageable.

Now in ZF, according to the dev, it would be possible to keep the existing application and switch it over piece-by-piece, e.g. by creating models for just a few database tables, then using calls to those models instead of calls to our current slim abstraction layer, etc.

Now I'm wondering whether such an approach would be possible with CI. Can I move my app over piece-by-piece, while keeping it running at all times?


Or, as a simple starter: Can I call CI models from a non-CI application? Can I launch views? Or would the controllers have to be the place to start any refactoring?
#2

[eluser]TheFuzzy0ne[/eluser]
I don't see why not. You might be able to create a controller that serves pages from the old site, and incorporate some routes. Without knowing anything else about your application structure, it's hard to be more specific.
#3

[eluser]Dam1an[/eluser]
You can use the views using a good old fashion include
As for the models, they have dependencies within the CI stack such as the base Model, the database and active record classes etc, so if you plan on using models like they would be used within CI, but outside of CI, you could need to stub part of this, or manually load the dependencies.

I would personally recommend starting from the controllers, creating functios for each page, and then calling the code you execute in the current systen... you can then move from there
#4

[eluser]Tom Vogt[/eluser]
[quote author="Dam1an" date="1241554726"]I would personally recommend starting from the controllers, creating functios for each page, and then calling the code you execute in the current systen... you can then move from there[/quote]

Yeah, I was afraid of something like that. It would mean I have to setup 500 controllers. Even if they're all stubs, that's non-trivial, especially since I need input data from the global variables that CI trashes.
#5

[eluser]Tom Vogt[/eluser]
[quote author="TheFuzzy0ne" date="1241554247"]I don't see why not. You might be able to create a controller that serves pages from the old site, and incorporate some routes.[/quote]

Routes might be a solution. What exactly did you have in mind?


My current application structure goes roughly like this:

Directory with lots of scripts in it.
Most scripts start with something like:

Code:
require_once('init.inc'); // this takes care of the session stuff and includes of global variables and functions

// some tests if this function is available at this time, access rights are there, etc.

if ($dosomething) {
   // whatever action
} else {
   // display available actions and let user choose, calling this script again
}
#6

[eluser]TheFuzzy0ne[/eluser]
I'm sorry, what made sense then, doesn't seem to now... Especially with regards to sessions. CodeIgniter doesn't use native PHP sessions, but your app does, so I predict problems if you try to mix and match them.

Is there any reason why it must be done like this? Can you not just keep the site as it is, and port it over to a site on your development server one bit at a time?
#7

[eluser]Tom Vogt[/eluser]
[quote author="TheFuzzy0ne" date="1241562791"]Is there any reason why it must be done like this? Can you not just keep the site as it is, and port it over to a site on your development server one bit at a time?[/quote]

It's a constantly-evolving online game. Porting it over bit-by-bit would mean that the older parts are outdated before we're done, or maintaining two codebases for every change. Both are inacceptable due to limited developer ressources. In-place replacement is the only thing that'll work. We've already had a failed attempt at rebuilding the current application from scratch.


I know CI fairly good, and ZF not at all, but if ZF can be used in this modular way and CI can't, then I'll probably have to learn ZF as well. But before doing that I want to find out whether CI maybe _can_ do this, after all.
#8

[eluser]TheFuzzy0ne[/eluser]
Oh, I see. That had never occurred to me. I know it's possible, but my mind is drawing a blank as to how. I, for one, will have to get back to you on this. Sorry to disappoint.
#9

[eluser]Dam1an[/eluser]
[quote author="Tom Vogt" date="1241562036"]Yeah, I was afraid of something like that. It would mean I have to setup 500 controllers. Even if they're all stubs, that's non-trivial, especially since I need input data from the global variables that CI trashes.[/quote]

I doubt you would need to make 500 controllers, as controllers define groups of pages, and each function in a controller is a page

Maybe you could do one controller at a time, redirecting from the old site to CI?
#10

[eluser]TheFuzzy0ne[/eluser]
I've been thinking about this, and I think you need to intercept it at the index.php. I think the index.php needs to be part CodeIgniter, and part Your Existing App. Merging the two files together, with some logic that maybe checks CodeIgniter for the appropriate controller, and if it's not there yet, your existing app handles it. Effectively, the index.php will be a controller of sorts.

When you're done, you'd convert back to the original index.php that came with CodeIgniter.

Hopefully this makes sense.




Theme © iAndrew 2016 - Forum software by © MyBB