magento display request url

18,853

Solution 1

I was looking for this also, here's how to do it:

echo Mage::helper('core/url')->getCurrentUrl();

Solution 2

Hi you could try to output the following

<?php
    echo Mage::app()->getRequest()->getModuleName();
    echo Mage::app()->getRequest()->getControllerName();
    echo Mage::app()->getRequest()->getActionName();
?>

Not tested but maybe you can do something like this

<?php
    echo Mage::app()->getRequest()->getRequestUri();
?>

Hope this helps

greetings

Solution 3

I needed the URL segments, so I used this:

function getUrlSegment($i) {
    $_baseUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
    $_currentUrl = Mage::helper('core/url')->getCurrentUrl();
    $_path = str_replace($_baseUrl, '', $_currentUrl);
    $_segments = explode('/', rtrim($_path, '/'));
    return $_segments[$i];
}

// Would get 'store' if URL: http://example.com/store/product/123
$root = getUrlSegment(1); 
Share:
18,853
kapitanluffy
Author by

kapitanluffy

Updated on June 27, 2022

Comments

  • kapitanluffy
    kapitanluffy almost 2 years

    i wanted to display the module,controller,method being called

    i thought that the cms module found in the

    app\code\core\Mage\cms\

    calls the IndexController.php and uses the IndexAction method .since it is the default page url.

    but when I tried to echo out something inside the IndexAction method .nothing comes out. I even tried to call it manually and it still redirects to the home page.

    localhost/magento/index.php/cms/index/index/

    am i doing it right? how can i display the request url being called in magento?