-3

This question is maybe made in the past, but I can't find a reference or a best practice for it. I was researching best ways to get it and I just find php includes or angular web apps etc but not best practices or what it normally developers do to create their websites, I never worked on a developing enviroment so I don't know what is the best way to create a website just reducing amount of innecesary code, that's maybe a subjective question, but I'm kind of new on this, I'm trying to create a multipage clothing website, it will have so many pages and I need to know what the best practice to create it... the website have a header and footer wich repeats on every page so I need to reduce code just making modules, but I don't know how to approach this and I don't really like to use CMS

in this link: stackoverflow question they just give option but what is actually the best practice for it??

Community
  • 1
  • 1
Kenny Amaro
  • 473
  • 1
  • 3
  • 14

2 Answers2

2

Try to think in what different kinds of pages you are going to have. Talking about a clothing store you are going to have for sure a home page, product-list pages in wich you list products related to a category, product pages where you show information about a particular product...

The thing is you need to identify all this kind of diferent document types you are gonna need and make a basic structure for each one, and then pull information dinamically from a database depending on the specific information you want to retrieve.

For example, if you are in a particular T-shirt page, you could fetch information from whatever type of database using whichever programming language and fill that "product page" with that info.

So it would be something like that common header and footer you had, and in the middle of them, the html template related to a product page, filled with database info related to a particular product (so you can show it's title, details and image for example).

So, depending on parameters you receive (from a clicked link for example), you select the neccesary info and show it in the corresponding template. Of course, all this logic has to be coded in the backend so you serve the final page.

Look for info about classical MVC model.

Just a side note from an ecommerce developer: Use some sort of software like Prestashop or Magento, building a custom ecommerce solution is not an easy task, take one of those and then customize it to fit your needs, they are already tested by thousands and maintained by pretty competent people. And ofc, you are going to find help easily.

Ricardo Zorzo
  • 289
  • 1
  • 9
1

Firstly an eCommerce website is not a simple feat and my first suggestion would be to simply use some of the pre-made eCommerce Solutions already out there (Shopify etc).

Secondly if you do wish to code it yourself, I recommend you have experience & knowledge in:

  • PHP, SQL and Web Languages (HTML,CSS,JS)
  • Object Oriented PHP

As a quick example that you may use to help you grasp the concept,

Firstly I would create my support files (Header, Footer, Database Connections)

Then I would create my Products Listing Page, here i list all my products. An each product would have an href="products.php?id=X" //where X is the ProductID.

What we just did was link all products to the products.php page and set a $_GET['id'] variable.

Then in products.php

<?php 
$ProductID = $_GET['id'];
// Then make your database calls for the Product
$Product = databasecallshere();
?>
<h1><?php echo $Product['Title']; ?> </h1>
<img src="<?php echo $Product['image']; ?>" />
<p><?php echo $Product['Description']; ?> </p>

Note though, this is very basic and messy and I would not use it in a production environment.

Look into .htaccess mappings and $_GET, $_POST php variables.

  • 1
    As Nathan points out, writing an eCommerce site from scratch is not something I suggest a beginner attempt. There are way to many security issues that even the "experts" have a hard time coping with. Instead, there are open source solutions, like Wordpress with ecommerce add-ons, OSCommerce, Magento, .. likely hundreds of options. Just Google "GPL ecommerce" – Duane Lortie Feb 16 '17 at 22:18