bluesomething Posted December 23, 2022 Share Posted December 23, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/315673-oop-feedback/ Share on other sites More sharing options...
Strider64 Posted December 23, 2022 Share Posted December 23, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315673-oop-feedback/#findComment-1603804 Share on other sites More sharing options...
menator01 Posted December 24, 2022 Share Posted December 24, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315673-oop-feedback/#findComment-1603854 Share on other sites More sharing options...
bluesomething Posted December 26, 2022 Author Share Posted December 26, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/315673-oop-feedback/#findComment-1603920 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.