2013-10-25

Creating Observer

Для обработки события добавляем в config.xml:
 <config>
...
 <adminhtml>
  <events>
   <adminhtml_catalog_category_tabs>
     <observers>
    <SliRx_CategoryAttachment_Model_Tab_Observer>
     <type>singleton</type>
     <class>SliRx_CategoryAttachment_Model_Tab_Observer</class>
     <method>addTab</method>
    </SliRx_CategoryAttachment_Model_Tab_Observer>
    </observers>
   </adminhtml_catalog_category_tabs>
  </events>
 </adminhtml>
...
 </config> 

Создаем соответствующий класс, с методом определенным в config.xml
public function addTab($observer) {
}



$observer  - Параметр который передается событию. Его параметры зависят от события, например $observer['tabs'].

<global> - If you want your observer to listen no matter where the event is dispatched from, put it here. You can also put it in "frontend" or "adminhtml".

<events> - This is the element that stores all of the events that are registered.

<adminhtml_catalog_category_tabs> - This is the "event" that you are listening to.

<observers> - This is the type of event. I don't think there are others.

<SliRx_CategoryAttachment_Model_Tab_Observer> - This is a unique string that defines this configuration. It can be anything, and just needs to be unique.

<type> - I have always used singleton, but other options can be "model" or "object". The "singleton" will create the object as Mage::getSingleton() while both "object" and "model" will use Mage::getModel() when creating the observer object.

<class> - This is the observer class.

<method> - This is the function to be called in the observer class.

No comments:

Post a Comment