Referencing scripts on different PHP pages

Asked

Viewed 76 times

0

I have the following structure:
|- /root
|-- /services
|--- /criminal records
|-- /view
|--- Dashboard.php
|--- php menu. |--- /registers
|---- /people
|----- Include_people.php
|-- /scripts
|-- js menu.

Inside Dashboard.php I have the following javascript: $("body"). load("menu.php") which is used to popular a navbar with the options.
- Inside menu.php I have the import of the menu.js file

The problem happens when I try to populate the same menu within "Inclu_people.php" because it is taking the path relative to that file (root/registrations/people). Even if I use in load the path ".. /.. /menu.php" it tries to find the menu.js in the directory for root/entries/people/.

There would be a way for me to import these files obsolutely, without having to leave all the files in the same directory?

1 answer

0

If it’s in a PHP file you could do something like this:

__DIR__ . '../../quantasPastasVocePrecisarVoltar';

the magic constant DIR serves to indicate the current path, then from the current path you return or advance folders normally as needed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.