2

I just started at developing extensions for Magento and trying to create a simple module that alert when the main page load.

So I created an extension in app/code/local/namespace/mymodule and PopupBlock.php file in block folder:

<?php die("1"); 
    class Michael_Popup_Block extends Mage_Core_Block_Template{
        die("1");
        protected function _construct()
        {
            die("1");
            parent::_construct();
        }
    }
?>

Also, in my etc/config.xml:

<?xml version="1.0" encoding="utf-8" ?>
<config>
    <modules>
        <Michael_Popup>
            <version>0.0.1</version>
        </Michael_Popup>
    </modules>
    <global>
        <blocks>
            <popup>
                <class>Michael_Popup_Block</class>                
            </popup>
        </blocks>
    </global>
    <frontend>
        <routers>
            <popup>
                <use>standard</use>
                <args>
                    <module>Michael_Popup</module>
                    <frontName>popup</frontName>
                </args>
            </popup>
        </routers>
    </frontend>
</config>

Why my block didn't load? how tell magento to load my block?
Thanks a lot!

2

The class name you give for blocks looks incorrect. Going by your file system path, it looks like your class needs to be defined as:

Michael_Popup_Block

Then when you are trying to load the block, it would be done as 'popup/popup'

The class name given for the actual class should reflect this as: Michael_Popup_Block_Popup and be saved in the Blocks/Popup.php file.

| improve this answer | |
  • Then when you are trying to load the block, it would be done as 'popup/popup'" do you mean in layout files? I want that my block load automatically... in any magento page... Do you understand what I mean? BTW: I edit my Question according your answer... thanks. – Michael May 17 '15 at 12:29
  • Yes the block type would become that in layout files. As to loading automatically on any page, you'll need to ensure you put it into a layout point that will be loaded across all pages. Likely under <default> – John Cuthbert May 17 '15 at 12:37
  • but I want to create an extension that not need to add any line in template file for install it. I create this extension for non-programmers guys. how it should work? maybe I'm mistake in my approach.. – Michael May 17 '15 at 12:52
  • In your extension you should declare an layout update file which will enable you to add the block to layout handles as needed. – John Cuthbert May 17 '15 at 15:28
  • in layout.xml should be in design directory right? in default package in default theme...? – Michael May 17 '15 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.