Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As several others have mentioned, splitting your code up into multiple PHP files can help you avoid duplicating your work unnecessarily. However, an even bigger benefit that can fall out of this is that the <code>include</code> statement is the gateway to providing is implementing a sitewide architecture such as <a href="http://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller" rel="nofollow">Model-View-Controller</a>.<br> Using MVC, your code is split up not just in terms of parts of the page that the user sees (header, footer, body, etc), but also in terms of responsibility. At a high level, the "Model" manages the data and business logic, the "View" handles the user interface (including rendering data from the model), and the "Controller" handles requests and interacts with the appropriate parts of the Model.<br> I'm no expert on MVC by any means, but the benefits here are enormous. Each of the components can be tested individually. Designing the components to be "loosely coupled" helps you avoid repeating yourself and encourages writing reusable code. There are a number of <a href="http://en.wikipedia.org/wiki/Model%E2%80%93View%E2%80%93Controller#PHP" rel="nofollow">PHP web application frameworks</a> that use MVC architecture, many of which are freely available (e.g., <a href="http://codeigniter.com/" rel="nofollow">CodeIgniter</a>).<br> Admittedly, MVC is not necessarily the "one true way" -- in your friend's case, implementing an architecture like this may be outside of the scope of what he wants to do. But in regards to your original question (in a roundabout sort of way I guess), the <code>include</code> statement can (when used properly) be a very powerful and useful tool. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload