2

i want to show custom url parameter in page created via module

what is did i created a module to show page with custom page

issue is how to pass and show parameter in url like product id of parent product

With my module i am able to open url with dummy content: like below

abc.com/related

i want to pass and show parameters like

abc.com/releted/productid/11

Below is code of my module MY_Related

1: app\code\local\MY\Related\Block\Index.php

<?php   
class MY_Related_Block_Index extends Mage_Core_Block_Template{   

}

2: app\code\local\MY\Related\controllers\IndexController.php

<?php
class MY_Related_IndexController extends Mage_Core_Controller_Front_Action{
    public function IndexAction() {

      $this->loadLayout();   
      $this->getLayout()->getBlock("head")->setTitle($this->__("Titlename"));
            $breadcrumbs = $this->getLayout()->getBlock("breadcrumbs");
      $breadcrumbs->addCrumb("home", array(
                "label" => $this->__("Home Page"),
                "title" => $this->__("Home Page"),
                "link"  => Mage::getBaseUrl()
           ));

      $breadcrumbs->addCrumb("titlename", array(
                "label" => $this->__("Titlename"),
                "title" => $this->__("Titlename")
           ));

      $this->renderLayout(); 

    }
}

3: app\code\local\MY\Related\etc\config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <MY_Related>
      <version>0.1.0</version>
    </MY_Related>
  </modules>
  <frontend>
    <routers>
      <related>
        <use>standard</use>
          <args>
            <module>MY_Related</module>
            <frontName>related</frontName>
          </args>
      </related>
    </routers>
        <layout>
          <updates>
            <related>
              <file>related.xml</file>
            </related>
          </updates>
        </layout>
  </frontend>
  <global>
    <helpers>
      <related>
        <class>MY_Related_Helper</class>
      </related>
    </helpers>
    <blocks>
      <related>
        <class>MY_Related_Block</class>
      </related>
    </blocks>
  </global>
</config> 

4: app\code\local\MY\Related\Helper\Data.php

<?php
class MY_Related_Helper_Data extends Mage_Core_Helper_Abstract
{
}
3

try related/index/index/product/11. Then you should be able to read the product param like this:

$product = Mage::app()->getRequest()->getParam('product');
  • what to do if i do not need double index/index – mdeveloper Jun 14 '16 at 12:42
  • then you need to create a custom router. take a look at this and try to adapt the answer to your needs. – Marius Jun 14 '16 at 12:44
  • can you help how can it be fixed using router – mdeveloper Jun 14 '16 at 12:47
1

To get all the parameters from the url related/index/index/product/11/id/4 then you can use this:

$product = Mage::app()->getRequest()->getParams();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.