Database call at Smarty / views / templates
At work today, someone tried to convince me that:
{$obj->getTableInfo()}
works great for smarty / mvc / templating since the object method is used. I argued that since it is making a call to the database, it has no place there and it should be in the controller (we are not actually using MVC). Am I correct in my understanding of logical sections that are used in MVC and in templates in general? Or is there something I am missing?
source to share
Well, there are no "official" rules or anything else, but I think something like this belongs to the controller. I am not doing anything in my code of view other than the mapped variables, no more complicated than a type loop is allowed if
or foreach
. Of course, not calling functions that call the database. All of this has to be loaded by the controller, the view only has to decide if it needs to be displayed or not.
source to share
Depends on its context and scope.
Is $ obj a controller or model layer? This should answer whether it really is in my opinion.
In response to reading other answers.
The function name itself refers to a simple getter method. It can call db through the controller layer. I would say this is normal. Especially if he used some form of in-memory caching. (i.e. a getter is an installer since you only want to cache it when it's used once.)
source to share