Generally, you want to limit interaction with the database to your models. You use a Block
class to retrieve the data from the model and prepare it for rendering. In your template.phtml
file, you take the prepared data from the Block class and render it as needed. It is highly discouraged to generate HTML directly from the Block itself, as it makes the HTML hard to modify without editing or overriding the Block class. (I just ran into this with the Amasty Promo Items extension, and because the extension is in the local
codepool I had no choice but to hack it.)
Here is a brief summary of what each part of the Magento MVC system does:
- Controller: Receives the request, sends any necessary data to model, and tells the Block to render it's template.
- Model: Contains the logic to operate the extension and interact with the database through the Resource Model.
- Block Essentially the "View" part of the traditional MVC triad. Gets data from the model and prepares it for rendering via the template file.
- Helper: Contains generic functionality that does not fit into the model and can be used anywhere.
Note: This is very high-level overview of how I understand Magento 1 to work. If you need more details, I maybe able to offer a more in-depth explanation.