In my custom module, I have perform some logical calculations in block to get the value in frontend.

And also I need to get that value in model also.

So my question is, I call the block function in model file like


Is this is a correct way to call block inside model, if not please explain.


I would say creating a block instance inside a model in this manner would be considered fairly non-standard. Conventionally the block layer would use the model layer (either by instantiating directly, or by retrieving models from global state such as the registry), rather than the other way around.

It's a little difficult to advise without knowing exactly what the block custom/custom actually does. If it's a matter of sharing a piece of logic between a block and a model I would recommend moving the logic to a helper (or even another model), then calling the helper functions from both the block and the model.

If the objective is to simply be able to access some kind of calculated value, then you would be better off storing this somewhere global like the registry or a session.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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