Jump to content


Photo

Best framework for integrating rubbish code?


  • Please log in to reply
12 replies to this topic

#1 johnsmith153

johnsmith153

    Advanced Member

  • Members
  • PipPipPip
  • 709 posts

Posted 07 March 2013 - 02:20 PM

I have a site written in bad code. Everything is all thrown onto one page. The PHP is at the top (above HTML output) and the rest is at the bottom, but that's as good as it gets.

 

Which framework would allow integration of this site the best (or any advice as to doing this)?

 

Of course the whole lot could be re-written and of course I could just decide not integrate it, but I'm looking to improve all the client side stuff, but maybe just drop the PHP into one 'processing' file. The benefit to this I see is that I can gradually add improvements to the site and make use of the framework as I do it (and save time now). Over time the rubbish code would no doubt be reduced.

 

Also, I may re-do all database interaction. So the idea would be to start as though creating a completely new site (using the framework), but when it gets to writing PHP I would save a lot of time by just calling the flat-PHP code already produced, maybe changing one or two things though (e.g. DB interaction).

 

I'm sort of looking at learning Symfony2, so I suppose the question also is could I learn Symfony2 and then integrate this rubbish site later and kill two birds with one stone, or is Symfony2 not very good for integrating rubbish flat-PHP code (and maybe another framework is a better idea)?

 

The idea is to modernise it, but not re-do it - if possible.

 

Thanks for any advice.



#2 Hall of Famer

Hall of Famer

    OOP Fanboi

  • Members
  • PipPipPip
  • 315 posts
  • LocationIthaca

Posted 07 March 2013 - 07:15 PM

Id strongly recommend you to overhaul your script before applying them into frameworks, since its difficult to convert a spaghetti code into a neatly designed structure of script in one step. But anyway if you want to do it fast, Codeigniter seems to be the framework that integrates with non MVC script the best. 


Welcome to the world of OOPHP! In a perfect script, everything is an object. You cannot be perfect, but you can approach as close as can.

zog841.jpg


#3 Christian F.

Christian F.

    Advanced Member

  • Staff Alumni
  • 3,106 posts
  • LocationNorway

Posted 08 March 2013 - 07:03 AM

No, no and no. CI is one of the worst frameworks to use, especially for learning purposes.

What I would recommend you do to, John, is to find a small and light-weight framework. One which you feel comfortable with, and then work to rewrite your logic to it. Laravel or Symfony 2 are some of the most commonly recommended frameworks, and Yii is another candidate. You can find a list of others at Wikipedia.

Edited by Christian F., 08 March 2013 - 07:04 AM.

Keeping it simple.

#4 johnsmith153

johnsmith153

    Advanced Member

  • Members
  • PipPipPip
  • 709 posts

Posted 08 March 2013 - 09:22 AM

Thanks for the advice. I still think Symfony 2 is a good choice, although I was under the impression Symfony2 wasn't considered light-weight. Regardless, I like what I see so far.

 

John



#5 annaharris

annaharris

    Advanced Member

  • Members
  • PipPipPip
  • 56 posts

Posted 01 May 2013 - 06:46 AM

I am agreed with Hall of Famer, Codeigniter works perfectly for our requirements.



#6 jeapie

jeapie

    Member

  • Members
  • PipPip
  • 10 posts

Posted 27 May 2013 - 10:31 AM

I recommend you to use micro-framework if you want to deploy your old code fast.

Silex or Slim.

They both have good and easy routing engines.

 

Your application for start will be like that.

require_once __DIR__.'/../vendor/autoload.php'; 

$app = new Silex\Application(); 

$app->get('/', function () {
    ... YOUR BAD CODE ....
})

$app->run(); 

And then you will rebuild it by adding new handlers for other routes



#7 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,664 posts
  • LocationMississauga, Canada

Posted 27 May 2013 - 11:54 AM

I recommend you to use micro-framework if you want to deploy your old code fast.

Silex or Slim.

They both have good and easy routing engines.

 

Your application for start will be like that.

require_once __DIR__.'/../vendor/autoload.php'; 

$app = new Silex\Application(); 

$app->get('/', function () {
    ... YOUR BAD CODE ....
})

$app->run(); 

And then you will rebuild it by adding new handlers for other routes

 

Really ???

 

What could be happened if your web root is different or the index is inside the project folder?



#8 salathe

salathe

    Badger

  • Staff Alumni
  • 1,859 posts
  • LocationEdinburgh, Scotland

Posted 27 May 2013 - 12:03 PM

Really ???
 
What could be happened if your web root is different or the index is inside the project folder?


Whaaaa?
PHP Documentation Team

#9 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 May 2013 - 12:29 PM

Seriously. If your directory structure is different, then you simply update the code to work with it, or update your directory structure. It's not rocket surgery.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#10 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,664 posts
  • LocationMississauga, Canada

Posted 27 May 2013 - 12:44 PM

Seriously. If your directory structure is different, then you simply update the code to work with it, or update your directory structure. It's not rocket surgery.

 

Not only the paths and the base web structure, this is a default routing provided by Silex and it's also related to Apache conf (if apache is your web server)

 

So....the best way is to start reading the documentaion of this library.


Edited by jazzman1, 27 May 2013 - 12:50 PM.


#11 Jessica

Jessica

    This is not my name.

  • Gurus
  • 8,982 posts
  • LocationDallas, TX
  • Age:26

Posted 27 May 2013 - 12:54 PM

Have you ever tried it? Because I have. I installed slim on my localhost in a non-root directory, and I didn't have to change a thing. It worked fine.
My goal in replying to posts is to help you become a better programmer, including learning how to debug your own code and research problems. For that reason, rather than posting the solution, I reply with tips and hints on how to find the solution yourself. See below for useful links when you get stuck.

How to Get Good Help: How to Ask Questions | Don't be a help vampire
Debugging Your Code: Debugging your SQL | What does a php function do? | What does a term mean? | Don't see any errors?
Things You Should Do: Normalize Your Data | use print_r() or var_dump()
Lulz: "Functions should not have side effects." - trq

Please take a look at my new PHP/Web Dev blog: The Web Mason - Thanks!!

#12 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,664 posts
  • LocationMississauga, Canada

Posted 27 May 2013 - 01:26 PM

Have you ever tried it? Because I have. I installed slim on my localhost in a non-root directory, and I didn't have to change a thing. It worked fine.

 

Yes, Jessi.

 

The first time when I run Silex was about a month I think, so the default routing did work at all and I've created my own Apache rewrite rule. 



#13 jeapie

jeapie

    Member

  • Members
  • PipPip
  • 10 posts

Posted 28 May 2013 - 02:23 AM

 jazzman, but still its a good way to solve current situation:

 

I have a site written in bad code. Everything is all thrown onto one page. The PHP is at the top (above HTML output) and the rest is at the bottom, but that's as good as it gets.

 

Topic starter can easily use twig for templates (separate HTML output), Doctrine DBAL for secure database integration and his php bad code will be in silex handlers.
I personally had such experience. It's much easier than rewrite it with full-featured framework with directory structure (Yii, CodeIgniter or ZF)






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com