0

I have the Magento in Version 1.9

Now I want to call some functions from my extension in product/view.phtml

My custom extension fetch data from Database and build some html fields, now I want to display in view.phtml.

Can you tell me, what is the best practice, because I have read that Helpers are not efficient for that.

1
  • Can you provide the code for your custom extension? Thanks! Commented Apr 7, 2016 at 13:05

2 Answers 2

0

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:

  1. Controller: Receives the request, sends any necessary data to model, and tells the Block to render it's template.
  2. Model: Contains the logic to operate the extension and interact with the database through the Resource Model.
  3. Block Essentially the "View" part of the traditional MVC triad. Gets data from the model and prepares it for rendering via the template file.
  4. 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.

0
0

You can use your custom Block php class file and prepare methods inside its class. Without this files you will only get things situated in your phtml file.

But without code it can be only general tip. You should especially show us layout update file, as we can see how or if you add any block.

If you are just editing core phtml, you are doing it wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.