I am trying to require a file, the script needs to require and then return a new instance (think that's the word) of that file. Simply i need to combine a namespace and a string.
--- EDIT ABOVE ---
Hey everyone i am trying to load my models like this:
But when i use
i get this error:
Here is the Test Class:
--- EDIT ABOVE ---
Hey everyone i am trying to load my models like this:
PHP:
public function loadModel($model)
{
require_once( dirname(__FILE__) . '/../models/' . ($model) . '.php');
$class = "Models\\$model";
return new $class($this->database);
}
But when i use
PHP:
$Test->loadModel('Test');
Code:
Fatal error: Cannot redeclare class Models\Test in C:\DevServer\data\localweb\app\models\Test.php on line 16
Here is the Test Class:
PHP:
<?php
/**
* Test Model.
*
* @package GarettMcCarty
* @author DrPepper23
* @link https://github.com/GarettMcCarty
*/
namespace Models;
use Exception;
if(class_exists('Test') != true)
{
class Test
{
protected $database = null;
public function __construct($connection = null)
{
try {
$this->database = $connection;
} catch(Exception $e) {
printf('Shit: %s', $e->getMessage());
exit;
}
}
}
}
?>
Last edited: