Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 750273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:31:55+00:00 2026-05-14T14:31:55+00:00

I have programmed with procedural style a lot before and in these few months

  • 0

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. 😀

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:31:56+00:00Added an answer on May 14, 2026 at 2:31 pm

    Create a Page class.

    Create a Category class. One of its attributes should be an array of Page objects named $pages (or similar).

    Create a method in the Category class called getPages() which will return the $pages array. If you like, this can be a “lazy-loading” method that gets the pages from the DB when it is called and caches them in the $pages attribute. Or you can load all the Page objects when the Category object is created. Your call.

    Create a method in the Category class called setPages($newArray) if you need or want to. This method should be used to overwrite the $pages array attribute with the value of the $newArray parameter.

    setX() methods are (traditionally) used to set the values of attributes, not to kick off DB lookups or other data generation schemes. They’ll look like this most of the time:

    public function setPages($newArray)
    {
        // data checking here to make sure $newArray is valid
        $this->pages = $newArray;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have programmed an emulator, but I have some doubts about how to organizate
I have recently programmed a console application and I've experienced a lot of pain
I'm a Java newbie, and also new to OOP. I have been a procedural
I think I am experienced procedural PHP programmer. I've implemented a few bigger projects.
Once I have programmed GUI with Java and have used Form Layouts. Form layout
I have been using oracle database throughout database courses, and I have programmed there
I have never programmed a gadget for Vista or Seven, but I would like
I have a webservice programmed in coldfusion which I'm attempting to consume using c#.net.
I have multiple IPs on a NIC. I've programmed a console application to connect
Possible Duplicate: Haskell vs. procedural programming in the real world Few times I heard

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.