How to convert a site into CI framework

#1
[eluser]benners[/eluser]
I'm new to CodeIgniter and MVC approach but keen to use it for a old, badly coded site I'm just about to work on.

Is it practical to gradually convert a site into the CodeIgniter framework by rebuilding certain pages and functionality with CodeIgniter or does it need to be a complete re-build? If it is possible how would I go about this?

Thanks for reading.

#2
[eluser]jedd[/eluser]
Hi benners and welcome to the CI forums.

My gut feel is that if you're not hugely familiar with CI already, or at least with a comparable framework, that you'd be better off starting the project from scratch, pulling in small partials of code when and where you need to, but definitely approaching it as though it was a new project.

I think the trying to continuously integrate a half/half thing would just cause more grief than it'd be worth.

Of course, a lot comes down to your skill and also just how badly the old site was designed and coded. If it's really quite bad, and you're also not hugely familiar with the ins and outs of it as well, I'd say that is even more encouragement to basically start from scratch.

#3
[eluser]benners[/eluser]
Thanks for your comments Jedd.

I thought that might be the sort of advice I'd get. Unfortunately it doesn't look like I will have the luxury of a new build due to the urgency of some of the fixes, budget and size of the site.

Is there any more info you can give me or relevant Wiki on how to go about converting a site?

#4
[eluser]Phil Sturgeon[/eluser]
If this is a large site and needs to be done urgently then this is definitely not the right time to switch to CodeIgniter.

I can help give some advice for the switch as I have done this with a few times for very large applications, but you would be much better off learning CI on the side and converting when the pressure is off.

#5
[eluser]überfuzz[/eluser]
The worst cases I've dealt with I just copied the html using right-click/show source and saved them as view-files. For starters the controllers just loaded these. Everywhere some functionality more than just showing stuff were needed I displayed a Work in progress.

Now, with this quasi MVC structure I started to add on functions for login, sending form_mail, setting up templates etc. While doing this I placed everything in it's right place; view, controller and model.

However, there is more to it than just scrabble it together. My advice would be, get familiar with CI before you start messing with an evil site. Chances are that CI will turn evil on you if you don't...

#6
[eluser]benners[/eluser]
Thanks to everyone for their comments.

I will certainly be cautious about any attempt to convert the site and I'll be elisting the help of someone more experience of the MVC approach. I'm thinking that the front of the site is relatively simple compared to the backend so we may be able to re-build that completely in CI and perhaps the backend we can just change bits and host them in a different locations.

#7
[eluser]überfuzz[/eluser]
A bit of advice on your way, make a simple site with a couple of pages just to get the feel of it. Before you start with the live site.

#8
[eluser]n0xie[/eluser]
How we migrated a rather big site:

Put the whole site in a subfolder of your root web folder, and use .htaccess to rewrite all requests to the subfolder (we named it 'oldsite' but any name will do). Be wary of absolute file paths (do a find on the entire codebase to look for any file that uses the filesystem). Make sure everything works before you continue any further.

Now setup your CI site in the root of the webfolder. Make sure the .htaccess still routes all traffic to the old site.

Now overwrite the Router class with a MY_Router. Let CI check if there is a controller present which matches against the url (the way it normally does). If not, redirect to the oldsite folder. Remove the .htaccess rule that redirects all traffic to the old site.

Now every request will go through the CI index.php. The Router Class will test if a controller exists for the requested url. (just like it would normally so you can user your routes in your config folder). If it won' t find one, normally CI would return a 404. Instead it now redirects the request to the old site.

Now you can slowly migrate parts of the website. Since the CI controllers take precedent over the old website, you can slowly replace parts of the old websites, and add new features as you would a normal CI site.

One word of caution. This will seriously impact any pagerank google has given to your website, since google doesn't like redirects. To counter this you can use your .htaccess to rewrite old urls to the 'oldsite' subfolder, although the list could become quite large.

#9
[eluser]bigtony[/eluser]
You could also check out [url="http://codeigniter.com/wiki/site_migrate/"]Site Migrate[/url] from the Wiki to see if it might be suitable.

I have a complex legacy app which I wanted to convert to CI, and for me the Site Migrate above wasn't quite flexible enough, but it may be for simpler apps.

But thanks to n0xie for his post above, as it's given me a possible way ahead.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.