Jump to content

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

Link to comment
Share on other sites

  • 5 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.