Banner

Tuesday, 20 January 2015

Creating a magento component from scratch

http://stackoverflow.com/questions/3526408/creating-a-magento-component-from-scratch


I first create a xml in the app etc...
<?xml version="1.0"?>
<config>
    <modules>
        <mywebwow_AdvancedCatalog>
            <active>true</active>
            <codePool>local</codePool>
        </mywebwow_AdvancedCatalog>
    </modules>
</config>
Then I create my folder in the local pool
/local/mywebwow/AdvancedCatalog/
In that folder I put the following files
/Block/AdvanceCatalog.php
/controllers/indexController.php
/etc/config.xml
I put the following in the block

AdvancedCatalog.php

<?php
class mywebwow_AdvancedCatalog_Block_Advancedcatalog extends Mage_Core_Block_Template
{
    public function _prepareLayout()
    {
        return parent::_prepareLayout();
    }

    public function getHelloworld()
    {
        return 'Hello world';
    }
}

indexController.php

<?php
class mywebwow_AdvancedCatalog_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <mywebwow_AdvancedCatalog>
            <version>0.1.0</version>
        </myweboww_AdvancedCatalog>
    </modules>
    <frontend>
        <routers>
            <AdvancedCatalog>
                <use>standard</use>
                <args>
                    <module>mywebwow_AdvancedCatalog</module>
                    <frontName>advancedcatalog</frontName>
                </args>
            </AdvancedCatalog>
        </routers>
        <layout>
            <updates>
                <AdvancedCatalog>
                    <file>advancedcatalog.xml</file>
                </AdvancedCatalog>
            </updates>
        </layout>
    </frontend>
    <global>
        <blocks>
            <AdvancedCatalog>
                <class>mywebwow_AdvancedCatalog_Block</class>
            </AdvancedCatalog>
        </blocks>
        <helpers>
            <AdvancedCatalog>
                <class>mywebwow_AdvancedCatalog_Helper</class>
            </AdvancedCatalog>
        </helpers>
    </global>
</config>
when i type in website.com/index.php/advancedcatalog/
I get a 404. no page found.
[EDIT]
I changed the block class from MyWebwow_AdvancedCatalog_Block_AdvancedCatalog to MyWebwow_AdvancedCatalog_Block_Advancedcatalog
I added advancedcatalog.xml it looks like the following...

advancedcatalog.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <advancedcatalog_index_index>
        <reference name="content">
            <block type="advancedcatalog/advancedcatalog" name="advancedcatalog" template="advancedcatalog/helloworld.phtml" />
        </reference>
    </advancedcatalog_index_index>
</layout>
then there is the following which I already had
/template/advancedcatalog/helloworld.phtml

helloworld.phtml

<h2><?php echo $this->getHelloworld(); ?></h2>

No comments:

Post a Comment