1

I need to get data from url and pass it block method for some operation. Basically i need to list some content on specific id in magento.

my controller function is
----------------------------

        public function showArchiveAction() {

            $id = $this->getRequest()->getParams('o');
            $this->loadLayout();
            $this->renderLayout();
          }

my block method
----------------
public function getMagazine($id)
     {

      $defaultMagazine = Mage::getModel('magazine/display')->getCollection()->load($id);
      $data = $defaultMagazine->getData();
      $defaultMagazineId = $data[0]['magazine_id'];
      $collection = Mage::getModel('magazine/page')->getCollection()->addFieldToFilter('magazine_id',$defaultMagazineId);

      return $collection;
      }
1

It seams like you are getting the id right.
You have 2 options here to send the data to the block.
Option 1 - Using register.

public function showArchiveAction() {
    $id = $this->getRequest()->getParams('o');
    Mage::register('current_magazine_id', $id);//register the id
    $this->loadLayout();
    $this->renderLayout();
}

Then you can read the id in the block or the template:

$id = Mage::registry('current_magazine_id');
$magazine = $this->getMagazine($id);

Option 2 - assigning the id to the block.
For this approach let's say that you block has the name magazine_details in the layout.

public function showArchiveAction() {
    $id = $this->getRequest()->getParams('o');
    $this->loadLayout();
    $block = $this->getLayout()->getBlock('magazine_details');
    if ($block) {
         $block->setMagazineId($id);
    }
    $this->renderLayout();
}

Then you can read this value in the block or template like this:

$id = $this->getMagazineId();
$magazine = $this->getMagazine($id);
5
  • This means that there is no block with that name. You should take the first approach. It's easier – Marius Dec 8 '14 at 8:29
  • I don't really understand you new question. But please keep this website clean. Ask an other question and explain in details what are you trying to achieve. – Marius Dec 8 '14 at 8:36
  • I extended my question...pls read... – Deepak Kumar Dec 8 '14 at 8:43
  • I edited my question...can u read again – Deepak Kumar Dec 8 '14 at 8:57
  • I read it. But I don't understand what you mean. Like I said. PLease keep things separate. Don't put 2 questions in one. – Marius Dec 8 '14 at 9:01

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.