I have a basic MVC framework set up.
Problem is I have to pass the registry in the view to the Controller in order to call the database which is set in the registry. This does not seem to be the proper way.
Question how can I get the database instance in my model directly?
init.php:
$registry = new registry;
$registry->db = db::getInstance();
basecontroller:
protected $registry;
function __construct($registry) {
$this->registry = $registry;
}
RegoController class:
Class regoController Extends baseController {
var $folder = 'rego';
public function index()
{
$this->registry->template->show($this->folder.'/index');
}
public function view(){
$this->registry->template->show($this->folder.'/view');
}
....
I have access to the db in this regoController
as it extends the baseController
.
my rego class (where I need the db instance):
class rego {
private $registry;
private function __construct($registry) {
$this->registry = $registry;
}
public static function getAllData($registry,$order){
$sql = "SELECT * FROM rego_details ORDER BY ".$order." ASC";
$db = $registry->db;
$stmt = $db->prepare($sql);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return $results;
}
As you can see the registry is passed as parameter in the function. This does not seem right.
Should I just extend the regoClass
or ...?