开发者

Magento Module IndexController - IndexAction function 404's

开发者 https://www.devze.com 2023-03-20 15:16 出处:网络
Removing the Class around the IndexAction causes a server error, so I know the code is running as expected up to that point.

Removing the Class around the IndexAction causes a server error, so I know the code is running as expected up to that point.

class Foo_Bar_IndexController extends Mage_Core_Controller_Front_Action{
    public function indexAction(){
        echo "<h1>Echo from indexcontroller.</h1>";
    }
}

Ideally the echo would be replaced by loading template files, but I've been stuck on it 404ing for the last 2 days and just want to get past that.

I've read through about a dozen tutorial, followed 4 to completetion, but this issue pops up every time. Does anyone have an idea what could be causing this?

Edit-- Sorry, for the brevity. I wasn't sure how much I should distend the page.

@ Alan Storm -- I found your tutorial here. http://alanstorm.com/magento_controller_hello_world (Great Detail, very helpful in understanding what all the xml tags do). This is a copy of that tutorial with Foo replacing Alanstormdotcom and Bar replacing Helloworld. Even copy/pasting I end up with the same 404.

Here is my current config file: PATH: app/code/local/Foo/Bar/etc/config.xml (edit: corrected path)

<config>
<modules>
    <Foo_Bar>
        <version>0.1.0</version>
    </Foo_Bar>
</modules>
<frontend>
    <routers>
        <bar>
            <use>standard</use>
            <args>
                <module>Foo_Bar</module>
                <frontName>bar</frontName>
            </args>
        </bar>
    </routers>  
</frontend>
</config>

Edit--- the last remaining file Path: app/etc/modules/Foo_Bar.xml

<config>
<modules>
    <Foo_Bar>
        <active>true</active开发者_如何学运维>
        <codePool>local</codePool>
    </Foo_Bar>
</modules>
</config>       


I think you are missing to add store_code in URL ( I had the same issue ), probably you have enabled the store code from admin in other words the store code (Ex: en, nl, etc) is adding in URL.

Ex :

www.example.com/en/aaa.html

If so, then please access your controller and action in this manner:

www.example.com/store_code/front_name/controller/action

Ex :

www.example.com/en/bar/index/index


Your path is incorrect:

app/etc/modules/Foo/Bar/etc/config.xml

You should place your module's definition file Foo_Bar.xml in app/etc/modules and the code of your module in app/code/local:

app/code/local/Foo/Bar/etc/config.xml
app/code/local/Foo/Bar/controllers/IndexController.php

EDIT: in order to access your controller you should access this url:

www.example.com/magento-instance/bar/index

Following this pattern:

{magento_root}/{magento_module}/{magento_controller}/{magento_action}


If other answers do not help you, you might want to try this path pattern:

     www.example.com/index.php/frontName/controllerName/actionName

I do not understand why they didn't create a rewrite rule for this kind of urls.

Anyway, the pattern above should work in most cases.

0

精彩评论

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

关注公众号