Skip to content

Instantly share code, notes, and snippets.

@BinaryGeometry
Created April 16, 2014 07:24
Show Gist options
  • Select an option

  • Save BinaryGeometry/10823481 to your computer and use it in GitHub Desktop.

Select an option

Save BinaryGeometry/10823481 to your computer and use it in GitHub Desktop.
Passing Url Parameters from Magento Controller to Block view.If you
class Binarygeometry_Tallgallery_AjaxController extends Mage_Core_Controller_Front_Action
{
public function indexAction ()
{
//URL EXAMPLE tallgallery/ajax/index?prodid=187&&imagid=551
$productId = $this->getRequest()->getParam('prodid'); // get product id from url
$imageId = $this->getRequest()->getParam('imagid'); // get image id from url
$imageSize = $this->getRequest()->getParam('resize');
Mage::helper('catalog/product')->initProduct($productId, $this); // make available to layout
$this->loadLayout(); // load the layout
$block = Mage::app()->getLayout()->getBlock('root');
if ($block){ //check if block actually exists
$block->setImageId($imageId); // pass parament to view
$block->setImageResize($imageSize);
$block->setData('field',$imageSize);
}
$this->renderLayout(); // render view
}
}class Binarygeometry_Tallgallery_AjaxController extends Mage_Core_Controller_Front_Action
{
public function indexAction ()
{
//URL EXAMPLE tallgallery/ajax/index?prodid=187&&imagid=551
$productId = $this->getRequest()->getParam('prodid'); // get product id from url
$imageId = $this->getRequest()->getParam('imagid'); // get image id from url
$imageSize = $this->getRequest()->getParam('resize');
Mage::helper('catalog/product')->initProduct($productId, $this); // make available to layout
$this->loadLayout(); // load the layout
$block = Mage::app()->getLayout()->getBlock('root');
if ($block){ //check if block actually exists
$block->setImageId($imageId); // pass parament to view
$block->setImageResize($imageSize);
$block->setData('field',$imageSize);
}
$this->renderLayout(); // render view
}
}
block phtml
<?php
$product = $this->getProduct(); // cache the product
$imageId = $this->getImageId();
$imageSize = $this->getData('field');
$imageGallery = $this->getGalleryImages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment