2
Filing cabinet menu.php
:
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="#"><img src="/imagens/logo.png"></a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#">Page 1</a></li>
<li><a href="#">Page 2</a></li>
<li><a href="#">Page 3</a></li>
</ul>
</div>
</nav>
Let’s say I have to add the menu in each *.php where there is a need for the page to have the menu, the best way is to make a include? For example:
- Let’s assume that we are in the root directory and we are in the index.php of this same directory, my own
include
would be on this path:include_once("Templates/menu.php");
Now, if I create a directory called home
and create a index.php
within it (home/index.php), the path of include
above would stand: include_once("../Templates/menu.php");
, which would take a lot of work.
Is there any simplified way to make a include of menu
, footer
etc more "experto"?
I was thinking about doing OOP
.
Yes. This is the best way if you are not using MVC.
– Diego Souza
With MVC, you can make the view always render the header and footer, in addition to the content you need, so you’ll need to give this include only once. Otherwise, you can set constants with the path and include the constant.
– Guilherme Lopes
The way you have shown it is already an "expert" way. rsrr You will have to do the includes anyway, with or without mvc or Oop. By the way, Oop and mvc have nothing to do with it. rsr
– Daniel Omine
Have you searched for templates engine? : - Twig - Mustache - Smarty
– rzani
If you do include with absolute path, you have no problem worrying about which directory is the file that uses include.
include_once( "$raiz_do_site_no_hd/Templates/menu.php" );
- Another good thing is to avoid capitalization on names. Do a DOCUMENT_ROOT search for more details on how to get the absolute path from the site root automatically.– Bacco