Archive for June 2017

Rendering layouts

hen we do toHtml(), we render only single block, for example in Adminhtml sorting, when we click on field we want to render only single block not whole page public function gridAction() { $this->loadLayout(); // $this->getResponse()->setBody( // $this->getLayout()->createBlock(‘storelocator/adminhtml_entity_grid’)->toHtml() // ); // return $this; } but if we dont do toHtml() and follow with renderLayout() then […]

Block – In Magento, a Block is a piece of your website works “alone”, you can insert just anywhere. In fact, a block is a kind of “mini controller” that you can add anywhere in your site. According to the page on your site, you can assign it different templates based on the view that […]

Database Connections In Magento

By default, Magento will automatically connect to it’s database and provide two separate resources which you can use to access data: “core_read” and “core_write”. <?php /** * Get the resource model */ $resource = Mage::getSingleton(’core/resource’);   /** * Retrieve the read connection */ $readConnection = $resource->getConnection(’core_read’);   /** * Retrieve the write connection */ $writeConnection […]

Difference between relative Db table and EAV table

ALL Magento Models inherit from the Mage_Core_Model_Abstract class. Difference starts from the Resource object. All resources extend the base Mage_Core_Model_Resource_Abstract class but simple Models have a resource that inherits from Mage_Core_Model_Mysql4_Abstract (Mage_Core_Model_Resource_Db_Abstract), and EAV Models have a resource that inherits from Mage_Eav_Model_Entity_Abstract

Adminhtml layouts

Adminhtml Grid and Edit is possible to add from layout or it is possible to specify directly in Adminhtml controller for example: this way: app/design/adminhtml/default/default/layout/photo.xml <?xml version="1.0"?> <layout> <adminhtml_photograph_index> <reference name="content"> <block type="photo/adminhtml_photograph" name="photograph" /> </reference> </adminhtml_photograph_index> <adminhtml_photograph_edit> <reference name="content"> <block type="photo/adminhtml_photograph_edit" name="photograph_edit" /> </reference> </adminhtml_photograph_edit> </layout> or this way: public function indexAction() { … […]

Magento explaining model naming

This: $model = Mage::getModel(’shop/people’); comes from: app/local/VendorName/PluginName/etc/config.xml <models> <shop> <class>VisionDirect_StoreLocator_Model</class> <resourceModel>storelocator_mysql4</resourceModel> </shop> <shop_mysql4> <class>VisionDirect_StoreLocator_Model_Mysql4</class> <entities> <people> <table>storelocator_people</table> </people> </entities> </shop_mysql4> </models>

How-to magento add Admin Backend Controller

1. Firstly, create adminhtml.xml file and put there and blocks within . Alternatively, you can put to config.xml -> block. 2. In order to have path to controller working propertly, never forget to add block in config.xml 3. Also, put to either adminhtml.xml or alternatively to config.xml block.

Reset admin password in Db

In case you forgot admin password it is possible to reset it directly in db: SELECT * FROM admin_user WHERE username=’admin’;   UPDATE admin_user SET password=MD5(’admin123’) WHERE username=’admin’;

Exception printing is disabled by default for security reasons

Rename the local.xml.sample in /errors to local.xml and you would be able to see the error and the entire stack trace

Disable cache

1. Go to Magento Admin Panel > System > Cache Management > Select all cache from left side checkboxes > Select Action: disable from right top dropdown > Click Submit