【问题标题】:magento display request urlmagento 显示请求地址
【发布时间】:2012-01-04 08:05:46
【问题描述】:

我想显示被调用的模块、控制器、方法

我以为是在

中找到的cms模块

app\code\core\Mage\cms\

调用IndexController.php并使用IndexAction方法。因为它是默认的页面url。

但是当我试图在 IndexAction 方法中回显某些内容时,什么都没有出现。我什至尝试手动调用它,它仍然重定向到主页。

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

我做得对吗? 如何显示在 magento 中调用的请求 url?

【问题讨论】:

  • indexAction的“i”应该是小写的
  • 是的,所有这些都是小写的。 indexController 和 indexAction .
  • 好吧,IndexController 应该是大写 :) -> Namespace_Module_IndexController extends ... 和 IndexController.php

标签: url magento content-management-system controller request


【解决方案1】:

您可能会使用控制器中的回显在日志文件中收到“标头已发送”警告。而不是使用 echo 使用 Mage::log,例如

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

日志行应该出现在 /var/logs/system.log 文件中。

【讨论】:

  • 我应该把它放在哪里?我试着把它放在 head.phtml 中。我不知道把它放在哪个控制器中。
【解决方案2】:

您好,您可以尝试输出以下内容

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

未经测试,但也许你可以做这样的事情

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

希望对你有帮助

问候

【讨论】:

  • 回声法师::app()->getRequest()->getRequestUri(); - 是合法的,谢谢
【解决方案3】:

路由cms/index/index 只用于主页。其他标准页面,如“no-route”和“enable-cookies”,可选择由 IndexController 上的特定操作处理。其余页面由Mage_Cms_PageController::viewAction() 处理。试试路径cms/page/view/id/customer-service 看看。参数为id,因此下一个术语customer-service 是您在管理员中设置为“URL Key”的页面标识符。

【讨论】:

    【解决方案4】:

    我也在找这个,方法如下:

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

    【讨论】:

    • 这对于获取完整的请求 URL 非常有用。
    【解决方案5】:

    我需要 URL 段,所以我使用了这个:

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

    【讨论】:

      猜你喜欢
      • 2022-01-20
      • 1970-01-01
      • 2011-04-20
      • 2011-07-31
      • 1970-01-01
      • 2021-11-10
      • 1970-01-01
      • 2015-03-13
      • 2012-05-18
      相关资源
      最近更新 更多