Jump to content

OOP feedback


bluesomething

Recommended Posts

I'm new in OOP php and started learning by checking out courses and tutorials with the mvc-model. Most is understandable. Then I started to check out how to use OOP on my website. The first thing I've wanted to change was to dynamically fill the social media tags by data that is used on multiple places of the website. I'm wondering if I'm on the right track.

So here are my thoughts:
There are three flavours, I think.
 1. the homepage, example: www.mywebsite.com
 2. a chapter, example: www.mywebsite.com/news
 3. a content item, example: www.mywebsite.com/news/winteriscoming
 
create a class called PageInfoModel: here I will select the url, image en titel of the page from the database, in case of the first 2 flavours
create a class called PageInfoView: contains properties url, title, image and a get and set method for the properties
A controller is not necessary.

In case of flavour 3 the properties need to be filled by a contentitem class, I think. So no duplicate code is made.

Is this the right way to go and if so, how do I do flavour 3?

Link to comment
Share on other sites

You might want to look at Active Record Design pattern if you are just building a small to medium website as I think it's easier to understand in my opinion.

I have a GitHub repository - https://github.com/Strider64/phototechguru of my personal website. Even if you don't use Active Record Design pattern it might give you some ideas.

Link to comment
Share on other sites

My understanding of mvc

model: handles all data such as get, add, and edit data. (From database or other form of data collection

view: pretty much presentation. shows data retrieved

controller: communicates between model and view.

Model has no knowledge of view and vise versa

controller is the go-between so to speak. controller has knowledge of both model and view.

sometimes controller may contain some presentaion

Link to comment
Share on other sites

Perhaps my description was not clear. The MVC-model, I understand. But in case of dynamically fill the social media tags this model doesn't fit one on one. So therefore my question about this section:

On 12/23/2022 at 11:14 AM, bluesomething said:

There are three flavours, I think.
 1. the homepage, example: www.mywebsite.com
 2. a chapter, example: www.mywebsite.com/news
 3. a content item, example: www.mywebsite.com/news/winteriscoming
 
create a class called PageInfoModel: here I will select the url, image en titel of the page from the database, in case of the first 2 flavours
create a class called PageInfoView: contains properties url, title, image and a get and set method for the properties
A controller is not necessary.

In case of flavour 3 the properties need to be filled by a contentitem class, I think. So no duplicate code is made.

Is this the right way to go and if so, how do I do flavour 3?

 

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.