CodeIgniter Forums
How to manager different projects with similar code? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to manager different projects with similar code? (/thread-14414.html)



How to manager different projects with similar code? - El Forum - 01-01-2009

[eluser]jaswinder_rana[/eluser]
Hi:

I have started using CI since December. I am on my second project now. Both of these projects have 60% similar code which includes CI, authentication, all styling, user control panel and admin control panel.

To start my second project, I simply copied first one, deleted files that were used ONLY in first project; which amounted to 6 files only.

Now, while developing second project, I found some bugs in the common code and I have been correcting it as I go along. It's becoming a pain to fix a bug and the copy the file back to first project.

My plans are to create one more project and then release all 3 together. I plan to do same thing with 3rd one.


Is there a way to organize the code to reduce this copying and pasting while I am developing?? All projects are totally different with 60% of similar code.

Modulation came to mind but as these are different projects (except that 60% code), it won't work for me.

I am hoping that there is a way that I can set my development environment (even for future) so that I can start developing right away by using same code and can apply the changes universally (and then just upload new code).

Please help (assuming I am making sense here Smile).

Thanks


How to manager different projects with similar code? - El Forum - 01-02-2009

[eluser]darkhouse[/eluser]
I don't know that I have a real solution, just some advice based on my experience. I'm in a similar situation, I've been using code igniter for a number of projects, and every time I started a new one I found I was just copying other sites and deleting anything unnecessary.

I decided that it would be smart for me to create a skeleton that I can use to build each site from, so I don't have to copy an entire other site. My skeleton includes things like user authentication, extended (and replacement) libraries (I changed Router and Form_validation), custom helpers and libraries. One library I built manages css and javascript files so I can easily load them on a per page basis.

I tried to keep everything "modular" so that it's easy to pick and choose what I need for each project. Now one thing to note, if I'm working on a new project and I add new functionality to the skeleton, I don't go back and change all of the other sites. So, each project ends up having a better core than the last. Unless there's a bug that needs to be fixed, then I would change it in all projects, but that hasn't happened yet (that I'm aware of).

So that's really all I can say. That's how I've been doing things, and it seems to be working pretty good. I've certainly cut down development time because of it.

If anyone else has any suggestions or solutions, I'd love to hear them as well.


How to manager different projects with similar code? - El Forum - 01-02-2009

[eluser]jaswinder_rana[/eluser]
Thanks.

I like the idea of skeleton. And about updating my old project, both are still under development and as I do different tests, I found few bugs (or different way to do things) which I keep on fixing.

But, lets say I have 2 projects and skeleton (under development). If I found a bug then I'd have to update it in 3 places and remember to do all changes.

I had another solution and not sure if it'll work or not. It's been a while since I used SVN. Maybe (not sure if it's practical), I can add my skeleton and checkout in different locations. Then when I submit a change then I can simply sync it to all locations and have the changes there.

Anyone has any experience with this?



darkhouse::
I was wondering if you can share you structure (only if you want to share it) which you say is modular. I am just trying to read up on different approaches and see if I can't improve my own.

Thanks


How to manager different projects with similar code? - El Forum - 01-02-2009

[eluser]darkhouse[/eluser]
The only issue with updating your skeleton and having it update all projects that use it is that it may break something else in a particular project. My thinking is, if your project works, then leave it alone. If you make changes to the skeleton, don't go back and apply the changes to the previous projects, just leave them with the old code.

In my case I have about 10 sites currently using CI, and I expect to use it for another 20 or so sites this year. I would hate to update each project, test each project, then fix each project just because I added some new feature to the skeleton. If the old projects work, they don't need to be updated, so I only apply the new skeleton to whatever project I'm working on at the moment.

As for my modular code structure, it's really just some libraries I wrote. I wrote my own user authentication which supports different user groups. I have a library for managing css and javascript files on a per page basis (as well as css and javascript snippets that aren't necessarily in their own files). I wrote a forwarding system, so if you need to be logged in before you can access a page, it redirects you to the login page and sends you back to the page you were on after a successful login. I built an output message system that allows me to easily write and display error messages and success messages. If you're not redirecting you can send messages to the library, but if you are redirecting, you can just set the messages in flashdata which the library will read upon reload. I think that's about it for things I've built myself...

The other things I've done is change the Router and Form_validation libraries. I didn't extend them, they are replacements. In Form_validation, I thought it was odd that you can set validation groups in a config file, but not directly in a controller, so I changed that. I don't think I'll ever use a config file for validation rules because most of my projects have a number of forms and things. It made more sense to set up groups from within the controller, but it wasn't working. I investigated and found out it just wasn't supported outside of a config file.

In the Router library, I changed it to allow multiple subdirectories (which I found code for in the forums here), and I also added in my own system which will eventually be used for a CMS in CI. What it does is instead of displaying a 404 when it can't find a controller, it sends the URI string to a CMS controller which will take that string and load whatever template, content, etc. I haven't finished that yet, but the Router part is working. We actually used this system for another site that we're converting from old crappy code to CI. We made it so for the pages we haven't converted yet, you can still use the same URI to access the page. The router can't find the controller so it loads the CMS controller, which then reads the content of the page (including any javascript and css) and displays it in our CI template. It worked really well. We were originally trying to do that with .htaccess so that if the URI contained .php but not index.php it would send the URI to a controller to grab the content of that page, but we couldn't get the .htaccess to work.

That's pretty much my skeleton right there. The only other thing is the Admin area which is a template and uses the user authentication system.


How to manager different projects with similar code? - El Forum - 01-02-2009

[eluser]jaswinder_rana[/eluser]
Thanks for the elaborated answer. It was helpful. I understand now the reason to not update old projects. I can now see the headache when things break in a nicely working project; clients won't be happy.

If someday you decide to release your code as Open Source Project then please let me know. I am very much interested to see how you do it.