Jump to content

How to layout this framework? (ecommerce page)


BrandonK

Recommended Posts

I'm doing a complete rewrite of a rather messy product page I wrote a few months back.  Since then I've done 2 other programs in my version of OOP.  I know that if anyone else looked at the code they would be confused at parts and laugh at parts.  I've read a couple books and I have a much better understanding of PHP's OOP (which is pretty different from the Java I originally learned on).  I've already looked at the features of the page and what I want it to do, etc., but I can't decide on how the framework should be done.

 

There are a couple functions that I think will make up the entire page.

Variable validation/URI parsing - pulls the variables out of the URI, validates and says these are the requirements for all products shown on this page.

Breadcrumb - Create a simple breadcrumb for each variable that we parsed.

Filtering menu - Using the variables parsed, give the user options for narrowing down the results even further.

Display results - Thumbnails of each product, etc.

 

There are some more functions obviously, but that should be enough for my question.  How would you set this up?  Is it possible or even logical to have the validation/parsing class create global variables?  Or would I be better off calling something like $parsing->getFilters() every time I needed access to them?

 

I'm still very new to the OOP designing.  I'm reading books, but it seems like there are always a couple unanswered questions once I put down the books and try to "fly solo".  Thanks in advance.

Link to comment
Share on other sites

Thanks for the link, Boo.

 

The question I was trying to ask (I think I beat around the bush too much with it though) is how should all of these different features interact?

 

I have a couple core functions:

- URI parsing - validating user variables, etc.

- Breadcrumb - all pages use a breadcrumb based on the array that was validated from 'URI parsing'.

- Filter menu - Look at the filters that were validated in 'URI parsing' and offer ways to narrow down the results further, or remove filters if there are some currently active.

- Display results - Using the filters that were validated in 'URI parsing', query the database and show the products that match every requirement.

 

In a perfect world, 'URI parsing' runs exactly once and each of the other functions can feed from that data.  The only thing that may be odd is that 'URI parsing' and 'Breadcrumb' is needed on a couple pages where 'Filter menu' and 'Display results' are not.  Because of that, I need to figure out how to design those two functions to be re-usable.

 

Knowing all of those details, should I be trying to write this as a single class with limited public functions to be called from the pages that need this information?  Or should I write this so that certain functions are in their own classes and each class interacts with another?  What worries me about that approach is how to I require steps to be taken (eg. 'URI parsing' has to be called first)?  I honestly don't see these functions being separate classes, they seem too dependent for that to work well.

 

I appreciate any input, thanks.

Link to comment
Share on other sites

Using the payam calls methods statically.

Which I don't think will work in this case.

 

I have my "URI parsing" class written already.  This will be the core function for my shopping pages (it decides the criteria and sorting for the products that will be displayed), so it should be processed on every page first.  From there my other functions, "breadcrumb" and "display results" will need to call the parsed variables.  What is the best way for me to do this?

 

$parseClass = new parseme();
$parsedArray = $parseClass->getParseData();

$breadcrumbClass = new breadcrumb($parsedArray);
$breadcrumbHTML = $breadcrumbClass->getBreadcrumbHTML();

 

or is there a better method? (I hope there is)

 

Thanks guys, you've been helpful.

Link to comment
Share on other sites

Using the payam calls methods statically.

 

can you elaborate?

Yes, it will call the class method (not the object method) statically. That is, it will not be a method of your object, and will not be able to maintain state data.

 

a brief example:

<?php

class FooBar
{
    public static $foo = 'foobaroo!';
    public $bar;

    public function __construct ()
    {
        $this->bar = 'foobar!';
        self::$foo = 'boofar!';
    }

    public function printit ()
    {
        if (!isset($this) || is_null($this)) 
        {
            print 'cannot print $this->bar';
        }
        else
        {
            print $this->bar;
        }
        print self::$foo;
    }
}

$fb = new FoorBar;
$fb->printit();
FooBar::printit();
?>

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.