A bit confused about OOP and PHP.

Posted by Pirkka on Stack Overflow See other posts from Stack Overflow or by Pirkka
Published on 2010-04-21T11:46:22Z Indexed on 2010/04/21 11:53 UTC
Read the original article Hit count: 260

Filed under:
|

Hello

I have programmed with procedural style a lot before and in these few months I have decided to go OOP.

Im a bit confused about OOP and PHP. Lets say I have Categories table and Pages table in my database. I would like to do a page-class and a category-class.

Lets say I would have a page that showed information about the category and there would be a list of pages that belong to the category. How would I implement that in OOP way?

I have thought that the category class would have a property (array) that would contain all the pages that it has. Well then comes the part that I`m confused about. Should I have a method that would get all the pages with correct categoryID from the database and should I instantiate all the rows as an Page-object?

Or should I have a setPages-method in the Category-class and getAllPages-method in the Pages-class and with that method I would set all the pages to the Category-class.

Huh Im lost. :D

© Stack Overflow or respective owner

Related posts about php

Related posts about oop