What's behind Magento? (2)
possibility to directly work with ZF API
ZF components like Zend_Lucene always available
part of Magento's core is enterprisephpcompliant
Events
Find out the events that Magento triggers:
cd app/code/core
grep r "dispatchEvent" . > /local/file/path.txt
Trigger your own event:
Mage::dispatchEvent('event_to_trigger',
array('myObject' => $this_module>domainObject));
CronStuff
Setup Magento's routine cronjob:
Crontab e
// here comes VIM
* * * * * path/to/php/binaries /path/to/magento/cron.php
Trigger a cronjob in your module config.xml to run a model method:
<jobs>
<mymodule_apply_all>
<schedule>
<cron_expr>0,30 * * * *</cron_expr>
</schedule>
<run>
<model>mymodule/modelName::modelMethod</model>
</run>
</mymodule_apply_all>
</jobs>
XML configurations
XML plays a dominant role in Magento runtime actions
They configure modules, layouts and routes
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
</default>
<news_index_index>
<reference name="content">
<block type="authors/authors" name="authors"
template="authors/authors.phtml" />
</reference>
</news_index_index>
</layout>
Models
Widelyused stuff
// loads any record of the model
Collection $products = Mage::getModel('catalog/product')
>getCollection()
// loads the row with id = ?
Single row $products = Mage::getModel('catalog/product')
>load(?)
// loads rows with is_active column value = 1
Filter $products = Mage::getModel('catalog/product')
>getCollection()
>addAttributeToFilter('is_active', 1)
Select // loads only the id column of the rows
$products = Mage::getModel('catalog/product')
>getCollection()>addAttributeToSelect('id')
Switch to ZF API $products_with_zf_api = $products>getSelect()
Blocks
Same as symfony's partials
$this>getLayout()>createBlock('module/template')
>setData('key', $value)
>setTemplate('myModule/myBlock.phtml')>toHtml();
Can reuse variables set in the controller
// Controller
Mage::register('key', $value);
// In any block
$key = Mage::registry('key');