Welcome Guest, Not a member yet? Register   Sign In
better approach to work with models
#4

(07-01-2021, 11:16 AM)tino Wrote: this may seems a stupid question, and probably it is.
let's say i have to print all the users who are verificated, would be better doing something like this:
PHP Code:
class UserController extends BaseController {

    public function showEveryUser() {
        $userModel = new UserModel();

        $users $userModel->where("is_verificated"1)->findAll();

        ...
    }


or creating a specific method in the UserModel like this:
PHP Code:
class UserModel extends Model {

    public function getEveryUser() {
        return $this->where("is_verificated"1)->findAll();
    }


and then calling UserModel->getEveryUser() in UserController->showEveryUser()?


In MVC format always use Queries in Model Section that is better practice. (We can reuse the code anywhere in the project by calling that particular model)
Reply


Messages In This Thread
better approach to work with models - by tino - 07-01-2021, 11:16 AM
RE: better approach to work with models - by [email protected] - 07-01-2021, 10:49 PM
RE: better approach to work with models - by tino - 07-02-2021, 02:54 AM



Theme © iAndrew 2016 - Forum software by © MyBB