Jump to content
Killersites Forums

Enquiry On How Inlcudes Work (PHP Shopping Cart with OOP & MVC Course)


Recommended Posts


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.
Link to comment
Share on other sites

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 by Drew2
Link to comment
Share on other sites

  • 1 month later...

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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