I have two classes, both in different namespaces. When i try to create the object from one namespace, then i get the error
Fatal error: Class 'Classes\DrDatabase' not found in C:\Path\to\workspace\AplicationName\app\models\Users.model.php on line XY
Is there something i did not understand with php namespaces?
the two files:
FILE 1
namespace Classes;
class DrDatabase extends MssqlDatabase {
public function __construct() {
parent::createLog(__CLASS__);
parent::connect('ipaddress', 'database', 'user', 'password');
if ($this->link) {
$this->log->info('Connected');
}
}
}
FILE 2
namespace Model;
use \Classes\DrDatabase;
class UsersModel implements MasterModel {
private function get($id, $onlyEnabled) {
$db = new DrDatabase();
$getOnlyEnabled = 1;
if (!$onlyEnabled)
$getOnlyEnabled = 0;
$SQL = "SELECT * FROM table";
$resultSet = $db->query($SQL);
$result = array();
while ($row = mssql_fetch_assoc($resultSet)) {
$result[] = self::createUserObject($row['col1'],$row['col2']);
}
}
}
Unless you’re using a properly configured autoloader you’ll still have to include “FILE 1” for it to work correctly.
Otherwise – How would your
UserModelknow where to find theDrDatabaseclass?