doushi4795 2015-01-16 15:09
浏览 101

PHP:如何从2个对象合并和设置方法

I have case study where I should display data from 3 table.

  1. User_Card Table

  2. Card Table

  3. Category Table

The query :

SELECT user_card_id, card_name, category FROM .... WHERE...

The query going well...

But when I try to set the selected data on setter, I have a little problem.. this is my code when I try to set.

                $cards = array();
                while($stmt->fetch())
                {   
                    $card = new UserCard();
                    $card->setUserCardId($user_card_id);
                    $card->setCardName($card_name);
                    $card->setCategory($category);
                    array_push($cards, $card);
                }

                $stmt->close();
                return $cards;

The code hint error because setCardName() and setCategory() is not on UserCard() object.

is that any way to do this without doing inheritance in UserCard object ?

update : **setCategory() is a member in Category Class

setCardName() is a member in Card Class should I merge it ?**

  • 写回答

0条回答 默认 最新

    报告相同问题?