5
votes

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?

5
the "i" of indexAction should be lowercaseOSdave
yup all of it are lower case. indexController and indexAction .kapitanluffy
well, IndexController should be UpperCase :) -> Namespace_Module_IndexController extends ... and IndexController.phpOSdave

5 Answers

11
votes

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

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

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

2
votes

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); 
0
votes

You might be getting 'headers already sent' warnings in your log files using an echo in the controller. Instead of using echo use Mage::log, e.g.

Mage::log('My request url is: '.$requestUrl);

The log line should appear in the /var/logs/system.log file.

0
votes

The route cms/index/index is only ever used for the home page. Other standard pages like "no-route" and "enable-cookies" are optionally handled by specific actions on the IndexController. The remaining pages are handled by Mage_Cms_PageController::viewAction() instead. Try the path cms/page/view/id/customer-service to see. The parameter is id and so the next term customer-service is the page identifier which you set in the admin as "URL Key".