Jump to content

Archived

This topic is now archived and is closed to further replies.

tomschwanland

Design for an online car configurator in PHP

Recommended Posts

Hi,

Essentially I know the theory for working in PHP, SQL, HTML, Sessions, etc. However, what I am missing is connecting the dots most efficiently.

I am trying to build a very simple online car configurator. The flow is:

  • user picks a brand
  • depending on the previous choice, user is presented with models, user picks one
  • depending on the previous choice, user is presented with model lines, user picks one
  • depending on the previous choice, user is presented with engines, user picks one
  • depending on the previous choice, user is presented with options, user picks 0-n options
  • user can submit a form that generates an email with all of the previously chosen options.

My current "design" works. But it is very nasty to maintain and I am sure there are better ways of going about it.

  • I have a single, monolithic PHP file where everything happens. I don't use any classes or functions. I don't use AJAX.
  • Data and GUI layer is all mixed up in the same file
  • I have one SQL data base with several tables. One for the models, one for the brands, etc.
  • Roughly the steps are as follows:
  1. Start session, check the phase the user is in by looking at what has been set already in the session E.g. if user has already selected a brand, models must be shown etc.
  2. SQL statement depending on phase, is executed to show all relevant items for that phase within the same PHP file.
  3. When a user clicks on any item, they simply call the same PHP page via GET (e.g. ?BrandID=2).
  4. That value is then stored into the same session.
  5. got to 1. for the other items.
  • My session variables are very simple and unstructured: $_SESSION['BrandID'], $_SESSION['ModelID'], etc.

I know this is a weird and sort of generic question. But I would love to know what the best practices are of how to structure this whole thing. How would you structure it?

  • should I use classes for the sessions, SQL queries, etc.?
  • Is there a better way than to use GET?
  • Should I have the SQL queries and or session logic defined in a separate file/function/class?
  • Separating GUI from data layer? How can this be achieved?

Input is greatly appreciated. Cheers!

Best regards,
Hans

Share this post


Link to post
Share on other sites

Hans,

In short -- MVC (Model, view controller). I'd suggest porting your existing code to a framework. The ones I currently would recommend looking at are Laravel or Symfony2 for a fullstack framework, or Silex or Slim for a micro framework. Considering where you are at present, a full stack might be better in that it will provide answers to questions you have rather than forcing you to first make a bunch of decisions about which components to use.

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.