0

My directory root:

src/ database.php Contact-Controller/ contact.php 

contact.php (None of these requires work):

require (__DIR__ . '/src/database.php'); require 'src/database.php'; require './src/database.php'; 

But on a other file

Directory:

src/ Search-Controller/ offer-count.php 

On "offer-count.php" is require 'src/database.php working with no Error 500.

I don't understand, why on some files work require 'src/database.php and on other files not. Where is the error?

1 Answer 1

3

You need to use .. to go to the parent directory of the current directory. So the correct way would be like this:

require '../database.php'; 
Sign up to request clarification or add additional context in comments.

1 Comment

Please, include som explanation of the magic constant __DIR__. Thank you. He will understand why his code was not working and will not make the same mistake again.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.