URL rewriting for Magento module

后端 未结 4 765
梦毁少年i
梦毁少年i 2021-02-10 15:49

I have created a New Module in Magento and named it as \"article\". It has two Front end controllers index and article.

And in the article controller i have an action ca

4条回答
  •  孤独总比滥情好
    2021-02-10 16:17

    Well, you might not be open to this option if you have several controllers in your module, but it is a valid solution without creating extra rewrite rules in your .htaccess, etc. It is possible to set your "articles" module up with an IndexController.php instead of an ArticleController.php. Then you could access the pages with [http://]mydemostore/article/archives/01/2011.... where archivesAction() is a method in the IndexController.php. Magento automatically maps the IndexController.php to /yourmod/index/ or just simply /yourmod/.


    Unfortunately, mydemostore/article/archives/01/2011 will NOT refer to the IndexController->archivesAction, but archivesController->01Action which will result in an error since method/function in PHP can only start with an underscore or a letter.

    However, the following urls will refer to the controller-action pair mentioned:

    • mydemostore/article/index/archives/
    • mydemostore/article//archives/

    Regarding the original question, saving programmatic URL rewrites within Magento would be the best practice, but not necessarily the most practical or quickest to implement; of course, Apache directives (e.g. .htaccess or site conf files) will be the quickest but not most observant of best practices.

提交回复
热议问题