Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Controller -> Layout -> Block relationship? 
 
cwchong
Jr. Member
 
Total Posts:  8
Joined:  2009-02-13
 

What I wanted to achieve:

I would like to add some codes to the OnepageController (ie checkout page) which checks the database for the number of orders thus far today, and then inform the current customer of expected delay if the number of orders exceeded a configurable limit.

What I thought should be done:

The indexAction function in OnepageController.php should be overloaded to make a database call, and perform some logic conditionals, and then set some flag somewhere, or trigger a function, so that the Onepage block or the onepage.phtml can retrieve the result and display the informational message.

However, I could not figure out how this is done. The call from OnepageController (or any controller) to trigger the loading of the page is almost magical (via loadlayout and renderlayout?). There is no call to any block, nor any call to any .phtml.

I tried $this->getLayout()->getBlock(’onepage’) but that didn’t work.

Can anyone show me a simple example of such a call?

What I did instead:

As I couldn’t figure out how to do the above, I put the database accessor and logics in the onepage block instead, and provide a accessor in the onepage block. The onepage.phtml can call the accessor function via $this->function()

This is horribly wrong as blocks shouldn’t access the database or hold the logics.

Anyone? smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
srinigenie
Guru
 
Avatar
Total Posts:  539
Joined:  2008-02-04
 

I am not able to exactly pinpoint and help you on this. But onepage does a lot of thing in AJAX. An easier way to check what you want and the flow is to install firebug on firefox and track the AJAX requests. I then think you would be able to easily locate the flow.

 
Magento Community Magento Community
Magento Community
Magento Community
 
demonkoryu
Guru
 
Avatar
Total Posts:  328
Joined:  2008-11-26
Dortmund, Germany
 

"I tried $this->getLayout()->getBlock(’onepage’) but that didn’t work.”
Almost. Blocks are referenced as module/block_subblock_subsubblock etc. So you have to use $this->getLayout()->getBlock(’checkout/onepage’).

“This is horribly wrong as blocks shouldn’t access the database or hold the logics.”
It happens often enough in the Magento code itself. I think it’s ok-ish as long as the database operation doesn’t modify anything. I’d extract such operations to a model, though.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top