I have a problem working with MVC patterns; I created multiple models, I'm using each one of them to handle grouped tasks(connection, DB, ect..).
Problem is, after creating the basic models, I ended up with code like this(within the controller).
class Controller
{
function doStuffz()
{
$accounts = new AccountsModel();
$DB = new DBModel();
$HTML = new HTMLModel();
//More models...
$accountData = $accounts->getAccount($id);
$DB->saveAccount($accountData);
$HTML->display($accountData);
//More code...
}
}
I've been creating instances of models within (almost) all functions in my classes, even though it seems absolutely fine to make them static.
I read this questions about when to use static methods, after applying the "rule-of-thumb" it seems all of these models should be made static, is that a bad practice in MVC patterns?
If I make these models static, I'll probably end up with something like this:
class Controller
{
function doStuffz()
{
$accountData = AccountModel::getAccount($id);
DBModel::saveAccount($accountData);
HTMLModel::display($accountData);
//More code...
}
}
Which actually makes more sense to me, also it looks much cleaner and shorter.