2

Here is my module's config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Teachers>
            <version>0.2.0</version>
        </Mycompany_Teachers>
    </modules>

    <global>
        <models>
            <mycompany_teachers>
                <class>Mycompany_Teachers_Model</class>
                <resourceModel>mycompany_teachers_resource</resourceModel>
            </mycompany_teachers>

            <mycompany_teachers_resource>
                <class>Mycompany_Teachers_Model_Resource</class>
                <entities>
                    <review_comment>
                        <table>mycompany_teachers_review_comment</table>
                    </review_comment>
                </entities>
            </mycompany_teachers_resource>

            <review>
                <rewrite>
                    <observer>Mycompany_Teachers_Model_Review_Observer</observer>
                </rewrite>
            </review>
        </models>

        <resources>
            <mycompany_teachers_setup>
                <setup>
                    <module>Mycompany_Teachers</module>
                </setup>
            </mycompany_teachers_setup>
        </resources>

        <helpers>
            <mycompany_teachers>
                <class>Mycompany_Teachers_Helper</class>
            </mycompany_teachers>
        </helpers>

        <template>
            <email>
                <mycompany_teachers_review_after_save module="mycompany_teachers">
                    <label>Video Comment: Email Teachers</label>
                    <file>mycompany_teachers/mycompany_teachers_review_after_save.html</file>
                    <type>html</type>
                </mycompany_teachers_review_after_save>
            </email>
        </template>

        <events>
            <review_save_after>
                <observers>
                    <mycompany_teachers_review_save_after>
                        <class>mycompany_teachers/review_observer</class>
                        <method>reviewSaveAfter</method>
                    </mycompany_teachers_review_save_after>
                </observers>
            </review_save_after>
        </events>
    </global>

    <frontend>
        <routers>
            <teachers_reviews>
                <use>standard</use>
                <args>
                    <module>Mycompany_Teachers</module>
                    <frontName>teachers_reviews</frontName>
                </args>
            </teachers_reviews>
        </routers>
    </frontend>
</config>

I've tried all of the following to get the controller URL:

Mage::getUrl('teachers_reviews');
Mage::getUrl('teachers_reviews/index');
Mage::getUrl('teachers_reviews/index/index');

All come back empty. I've tried changing both <teachers_reviews> and <frontName>teachers_reviews</frontName> to different things like so:

<frontend>
    <routers>
        <test>
            <use>standard</use>
            <args>
                <module>Mycompany_Teachers</module>
                <frontName>another</frontName>
            </args>
        </test>
    </routers>
</frontend>

And then tried:

Mage::getUrl('test');
Mage::getUrl('test/index');
Mage::getUrl('test/index/index');
Mage::getUrl('another');
Mage::getUrl('another/index');
Mage::getUrl('another/index/index');

And no matter what I try, Mage::getUrl comes back empty. I can go to example.com/teachers_reviews and I get the Hello World from my class:

<?php

class Mycompany_Teachers_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
        die('hello world!');
    }
}

I don't understand why I can't get Mage::getUrl to work.

4
  • Check ur Mage.php for function getUrl() whether it is commented in any case.. Dec 30, 2014 at 6:05
  • put log inside your indexAction() then check it is logged while trying this action. Dec 30, 2014 at 6:07
  • echo Mage::getUrl? I don't know man, there is nothing wrong with your code. Dec 30, 2014 at 6:18
  • what happens when you do this with some Magento controllers? I seem to see that this should not validate the path but simply format it. If it does not work with standard controllers then I suggest you have something more seriously wrong with your set-up Jan 24, 2015 at 13:38

2 Answers 2

2

This ended up being a combination of me correcting previous naming issues in the config.xml and changing the router along with those corrections, and then not clearing the cache.

1
  • Consider accepting a solution if it's solved.
    – WackGet
    Nov 29, 2017 at 19:20
2

For those suffering a similar problem, check and double-check your module's config.xml for the smallest naming errors, including case sensitivity.

Naming your router <lowercase_whatever> then trying to use getUrl("LowerCase_Whatever/CoolFunction") is not going to work.

When you use the getUrl() function, Magento eventually calls Mage_Core_Controller_Varien_Front::getRouterByRoute(), which tries to load routers in the order of admin routers first; then standard routers; then custom-named routers. That's what <use>standard</use> refers to in the question's XML above.

In this case, it'll try to load a standard router with the name test, thanks to the <test> XML block above. However, if you write it as <test> in the XML, but then call getUrl("Test/whatever") (note the case difference), it'll try (and fail) to load a standard router with the name Test instead.

TL;DR: check your text's case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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