ChanX
ChanX

Reputation: 372

Require Once Always Not Found even if Link is correct in PHP

I have a class file named Notes.php .It does have a namespace and when I do require_once it gives me a Warning Required file not found where as the url is correct and also. Below is the Class File

Directory tree is:

Class
    Notes
        Notes.php
    Database
        Db.php

Below is the class code

#Declare Namespace for the Notes class
namespace Dashboard\Api\Notes;

require_once '../Database/Db.php';

use Dashboard\Api\Database\Db;

class Notes {

    # Set Protected Properties
    protected $_db;
    public $username;

    function __construct () {
        $this->_db = Db::getInstance();
    }

    public function getNotes() {
        $query = "SELECT * FROM notes";
        $result = $this->_db->query($query);
    }
}

Upvotes: 0

Views: 41

Answers (1)

yergo
yergo

Reputation: 4980

Try __DIR__:

require_once( __DIR__ . '\..\Database\Db.php');

It may happen because you are using some .htaccess configurations etc.

Other useful constants: here.

Upvotes: 2

Related Questions