![]() |
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 { or creating a specific method in the UserModel like this: PHP Code: class UserModel extends Model { and then calling UserModel->getEveryUser() in UserController->showEveryUser()?
There's no right or wrong answer. It depends on how you want to organize your application. Personally I prefer to have the least possible logic in the controllers and in the models. I prefer to keep them simple and put most of the logic in a library. If your application is super small, it may be overkill to do it this way. But if you have a somewhat big application, it's easier to develop and to maintain when the logic is not everywhere in the controllers, the models, etc. It's also easier to reuse those functions if you need them in multiple places in your code. You can see an example of this in my tutorial for a basic application.
i dont do query on controller, all put in other class , more efficient (sometime same query need in different controller)
(07-01-2021, 11:16 AM)tino Wrote: this may seems a stupid question, and probably it is. 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)
I would personally also put it in a Model, running queries inside a controller is a no-go for me..
|
Welcome Guest, Not a member yet? Register Sign In |