Mage::getUrl Returns Admin URL Instead of Frontend URL in Magento 1.7

geturlhelpermagento-1.7router

I have create an extension which used frontend as well as admin end.
My config code is below.

<frontend>
    <routers>
        <testimonial>
            <use>standard</use>
            <args>
                <module>Magentohelper_Testimonial</module>
                <frontName>testimonial</frontName>
            </args>
        </testimonial>
    </routers>
    <layout>
        <updates>
            <testimonial>
                <file>testimonial.xml</file>
            </testimonial>
        </updates>
    </layout>
</frontend>
<admin>
    <routers>
        <testimonial>
            <use>admin</use>
            <args>
                <module>Magentohelper_Testimonial</module>
                <frontName>testimonial_admin</frontName>
            </args>
        </testimonial>
    </routers>
</admin>

When i Call

Mage::getUrl('testimonial/index/check/');

from my phtml file, It Returns the admin url which is testimonial_admin/index/check/
From the magento wiki i got the instruction to create extension, which says this
magento wiki module creation

I guess the router is matching the admin Url first.
How can i get the url of my frontend using Mage::getUrl function.?

Best Answer

The problem is that both the admin router and the frontend routers have the same node. Even if they have different frontNames. If you update your admin xml to the following:

<admin>
    <routers>
        <testimonial_admin>
            <use>admin</use>
            <args>
                <module>Magentohelper_Testimonial</module>
                <frontName>testimonial_admin</frontName>
            </args>
        </testimonial_admin>
    </routers>
</admin>

And then when you call Mage::getUrl('testimonial/index/check/'); you will get the frontend url and Mage::getUrl('testimonial_admin/index/check/'); will give you the admin urls.

Related Topic