Question

I'm trying to create one simple thing: Block which is referred by the layout file. But I spend a two hours and still couldn't detect where am I wrong.

Here is the config.xml:

<?xml version="1.0"?>
<config>
<modules>
    <AD_Donations>
        <version>0.0.1</version>
    </AD_Donations>
</modules>
<global>
    <blocks>
        <donations>
            <class>AD_Donations_Block</class>
        </donations>
    </blocks>
</global>
<frontend>
    <routers>
        <donate>
            <use>standard</use>
            <args>
                <module>AD_Donations</module>
                <frontName>donate</frontName>
            </args>
        </donate>
    </routers>
    <layout>
        <updates>
            <ad_donations>
                <file>ad_donations.xml</file>
            </ad_donations>
        </updates>
    </layout>
</frontend>
</config>

Here is a layout file (ad_donations.xml):

<layout version="0.1.0">
<donate_index_index>
    <reference name="root">
        <action method="setTemplate"><template>page/page_one_column_sidebar.phtml</template></action>
    </reference>
    <reference name="content">
        <block type="donations/category" name="donations" as="donations" template="donations/donations_category.phtml" />
    </reference>
</donate_index_index>
</layout>

And here is a AD/Donations/Category.php file:

<?php

class AD_Donations_Blocks_Category extends Mage_Core_Block_Template
{
    public function __construct()
    {
        Mage::log('1111');
    }
}

Here is my controller AD/Donations/IndexController.php:

<?php

class AD_Donations_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}

What's wrong here?

Was it helpful?

Solution

There small mistake in yours block class

class AD_Donations_Blocks_Category 

should be

class AD_Donations_Block_Category 

Also Category.php path location AD/Donations/Block/

Please check how create a extension: http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top