0

(PDO::FETCH CLASS, 'Product') を使用して入力し、各アイテムをページにエコーする製品クラスがあります。カテゴリごとにたくさんのアイテムがあります。これは、私の「カテゴリ別表示項目」ページで使用されています。

 class Product {

// All attributes correspond to database columns.
// All attributes are protected.
protected $productID = null;
protected $name = null;
protected $description = null;
protected $price = null;
protected $image = null;

// Method returns the product ID:
function getProductID() {
    return $this->productID;
}    

// and other methods to return each variable 
 }

次に、MVC モデルを使用して productID を渡すリンクをクリックして、1 つのアイテムをより詳細に表示する製品の詳細ページを表示します。上記の製品クラスと、以下に作成した子クラスからの情報。

次に、このクラスを、各製品のすべてのオプションを含む Stock クラスに拡張しました。つまり、サイズ、色、数量です。たとえば... 1 つの T シャツに 3 つの異なるサイズ、2 つの異なる色があり、これらのバリエーションごとに数量を指定できます。

同様に、PDO::FETCH CLASS メソッドを使用して Stock クラスに値を設定します。

拡張クラスは次のとおりです。

 class Stock extends Product{

// All attributes correspond to database columns.
// All attributes are protected.
protected $productID = null;
protected $qty = null;
protected $colour = null;
protected $colourHEX = null;
protected $sizeName = null;

// Method returns the product ID:
function getproductID() {
    return $this->productID;
}

// Method returns the product ID:
function getQty() {
    return $this->qty;
}

私の問題は、これらのクラスの両方を別々の Web ページで別々に作成したことであり、子から親クラスにアクセスする方法がわかりません。私は一日中これを理解しようとしてきました。ストックの子クラスと親の間の関連付けを作成していないことはわかっていますが、これを行う方法を考えられないため、親のメソッドにアクセスして名前、価格などを表示できます.

十分な情報を含めましたか?

本当に本当に困っています

4

0 に答える 0