开发者

Creating a magento component from scratch

开发者 https://www.devze.com 2023-01-12 02:54 出处:网络
I am trying to create a magento shopping cart module but things arent working out. Here is my steps I first create a xml in the app etc...

I am trying to create a magento shopping cart module but things arent working out. Here is my steps

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>


A few things to fix, hopefully one will get you moving:

  1. Move your controller from indexController.php to IndexController.php. On case-sensitive systems, this very well could cause the controller not to be found.

  2. Have you defined a layout file? (e.g. advancedcatalog.xml). Your file defines advancecatalog.xml, which seems like it might be a typo, though it could work if you defined that file.

  3. Do you have any views defined? loadLayout will try to load a layout handle for the page and render blocks accordingly. This is where you'll have to specify your advancedcatalog/advancedcatalog block. If you do have a layout and templates, please post those.

  4. Don't use camelcase for the block name, it will confuse Magento. The block will need to be defined as advancedcatalog/advancedcatalog, but that will resolve to mywebwow_AdvancedCatalog_Block_Advancedcatalog (note no second cap). This will be an issue.

Fix those and see if it starts working, let me know if you still have trouble.

Thanks, Joe


You don't necessarily need a model unless you are invoking one. As for #4, it's up to you whether you want to use mixed case on that one. In your config file, you specified the prefix for AdvancedCatalog blocks to be mywebwow_AdvancedCatalog_Block, so the mixed case shouldn't be a problem. Conversely, though, you may want the tag inside of blocks to be lowercased, so that when you invoke your models you can stick w/ the existing Magento convention of lowercase. Do this:

<global>
    <blocks>
        <advancedcatalog>
            <class>mywebwow_AdvancedCatalog_Block</class>
        </advancedcatalog>
    </blocks>
....


@numerical25: Also clean cache to get desired output (i.e.,) Go to system->cache management then flush magento cache..

0

精彩评论

暂无评论...
验证码 换一张
取 消