|
|
|
|
|
by ironkeith
5348 days ago
|
|
There are no comment on the blog, so I'm just going to put this here and hope the author sees it (as they appear to have submitted the post): You don't want to write SQL in your controllers. It's a recipe for future pain and suffering. - If a second action needs the same data, it's likely that you'll end up duplicating your query. Especially if you work with other people, and they don't know about the queries that exist in all of the different actions. - If you change the structure of the data in the DB, you need to find every affected query, in every action. It's extremely fragile, and prone to breaking. If you have a model, with a nice public API, that interacts with the DB, you know that you've isolated the change to just that one place. All of the controllers that call $model->some_data(); will continue to work no matter how your change your data source so long as you obey the API. There are million different ways you can approach that, but I strongly recommend that you find one that works for you, and stick with it. |
|
I think part of the reason for this is it appears in allot of tutorials for different web frameworks, which I think they do because it makes the code smaller and therefor their framework look simpler.