Saturday, 15 January 2011

What Is The Better Way To Customize A Core Block's After Prepare Layout in Magento? -



What Is The Better Way To Customize A Core Block's After Prepare Layout in Magento? -

all blocks in magento inherit abstract, , within fragment of code:

#file: app/code/core/mage/core/block/abstract.php   public function setlayout(mage_core_model_layout $layout) {     $this->_layout = $layout;     mage::dispatchevent('core_block_abstract_prepare_layout_before', array('block' => $this));     $this->_preparelayout();     mage::dispatchevent('core_block_abstract_prepare_layout_after', array('block' => $this));     return $this; }

there 2 ways hook onto prepare layout of core block:

rewrite core block own , create _preparelayout function calling it's parent , doing code after observe core_block_abstract_prepare_layout_after event , check if instance of block 1 interested in

the advantage sec event/observer patterns better, more stable selection implementing additional functionality. however, disadvantage observer have run every single block layout prepared.

which improve progamming technique here?

if rewrite abstract class block still utilize 1 in core, because straight extend , don't utilize magento rewrite rules. sec solution. observer on every block performance issue should not big, because in cases execute simple status instanceof, fast.

magento

No comments:

Post a Comment