【问题标题】:magento indexControllor.php url rewriting not working properlymagento indexControllor.php url重写无法正常工作
【发布时间】:2011-05-15 08:49:19
【问题描述】:

您好,我在这样的模块品牌中构建了一个索引控制器

class Blank_Brand_IndexController extends Mage_Core_Controller_Front_Action
{

    public function indexAction()
    {

        echo 'Foo Index Action';
        $this->addaction();
    }

    public function addAction()
    {
        echo 'Foo add Action';
        $this->deleteAction();
    }

}

当我输入地址时:http://www.myshop.com/index.php/brand/,它与 Foo Index Action 相呼应

但是,对于这个 URL,它什么都不做:http://www.myshop.com/index.php/brand/add

这里可能是什么问题导致了这种情况?这可以为我节省很多在 Magento 中重写 URL 时遇到的问题!

【问题讨论】:

    标签: php zend-framework magento


    【解决方案1】:

    这是一个常见的疏忽。

    这个网址

    http://www.myshop.com/index.php/brand/
    

    相当于这个url

    http://www.myshop.com/index.php/brand/index/index
    

    URI 部分“品牌”是您的模块。第一个“索引”URI 部分是您的控制器,第二个“索引”URI 部分是您的操作方法。

    Module:     brand
    Controller: index
    Action:     index
    

    那么,让我们考虑一下这个 URL

    http://www.myshop.com/index.php/brand/add
    

    这相当于

    http://www.myshop.com/index.php/brand/add/index
    

    这给了我们

    Module:     brand
    Controller: add
    Action:     index
    

    您尝试调用的 URL 正在寻找一个名为

    的控制器
    class Blank_Brand_AddController ....
    

    当它没有找到时,它会返回 404。

    如果您想在索引控制器上调用 addAction 方法,您需要以下 URL

    http://www.myshop.com/index.php/brand/index/add
    

    【讨论】:

    • 好吧,如果我也添加了一个参数表,函数 addAction($test)
    • 我将如何填写 $test 因为
    • 我也想知道我将如何传递索引中的变量...如果 $test 为 9 并且 add 函数不存在,那么完整的 url 会是什么样子...。因为我似乎在这里没有得到正确的 url...我想在 index 函数中传递 catid/3 但我该怎么做呢?
    • 请求变量不会通过操作方法参数进入控制器。调用“var_dump($this->getRequest()->getParams());”在动作控制器中,如何访问您的请求数据应该是不言自明的。此外,请通读知识库开发人员的教程。 magentocommerce.com/knowledge-base/entry/…
    【解决方案2】:

    【讨论】:

    • +1 以获得良好信息,但原始发帖人并没有试图覆盖任何内容。他们试图设置自己的控制器并被绊倒,因为它不像蛋糕或代码点火器那样工作。 (此外,现在有一种更好的方法来处理控制器覆盖:web-magician.blogspot.com/2009/04/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    • 2014-08-25
    • 1970-01-01
    相关资源
    最近更新 更多