I am new to Magento. I just want to know in which situation we write the code in Block directory? Why we cannt write same code in Controllers? I read articles for this but does not get the answer. Thanks in advance.

有帮助吗?

解决方案

Take a look @ Magento for Developers: Part 4 - Magento Layouts, Blocks and Templates

Unlike many popular MVC systems, Magento's Action Controller does not pass a data object to the view or set properties on the view object (with a few exceptions). Instead, the View component directly references system models to get the information it needs for display.

One consequence of this design decision is that the View has been separated into Blocks and Templates. Blocks are PHP objects, Templates are "raw" PHP files (with a .phtml extension) that contain a mix of HTML and PHP (where PHP is used as a templating language). Each Block is tied to a single Template file. Inside a phtml file, PHP's $this keyword will contain a reference to the Template's Block object

其他提示

We write the code in Block directory for creating blocks. Example: we need to show a block at the left sidebar. controller doesn't need for this.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top