fra168nk Posted November 7, 2020 Report Posted November 7, 2020 Hi, I am currently coding along with "PHP Shopping Cart with OOP & MVC" project on StudioWeb and I have a question on how includes work and I hope that anyone can help me. Basically I want to know how one page can magically have access to a specific class. In the video "Template Object: Part 2", timestamp 8:49, in the "v_public_home.php" file, Ben wrote "$this" because the view is being included in the Template object. I cannot wrap my head around how this works. It just seems to me that out of nowhere we can access the Template object. Can anyone give me a detailed breakdown on how the "v_public_home.php" file can have access to the Template object? Thank you. Quote
Drew2 Posted November 11, 2020 Report Posted November 11, 2020 (edited) Hello fellow coder fra168nk. I may have just figured out myself how include works. Imagine one document with the function of bouncing a ball. (D1) Then you have a second document with the request to actually bounce a ball (D2) For D2 to actually bounce a ball, it will need the help of D1. D1 is the tool with which D2 can bounce a ball. By writing, for example, include(D1) in D2, D2 now has access to the bouncing ball function in D1. D1 and D2 have become one document in a sense (in terms of one benefitting from the other). Although the documents are now one, in a sense, D1's location (as far as referencing CSS is concerned) is now wherever D2 is located. So, whenever a reference is made in D1 to CSS, it should be made as though D1's location is the same as D2's. It took me a while to figure that one out. Edited December 25, 2020 by Drew2 Quote
administrator Posted November 16, 2020 Report Posted November 16, 2020 On 11/6/2020 at 7:58 PM, fra168nk said: Basically I want to know how one page can magically have access to a specific class. He is important a reference (php page) where the class is defined. Quote
fra168nk Posted November 19, 2020 Author Report Posted November 19, 2020 On 11/17/2020 at 4:50 AM, administrator said: He is important a reference (php page) where the class is defined. Hi Stefan, Thanks for replying. "He"? Is that a typo? I still don't understand. Quote
administrator Posted December 22, 2020 Report Posted December 22, 2020 Looks like He is a typo. Quote
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.
Note: Your post will require moderator approval before it will be visible.