Created
April 16, 2014 07:24
-
-
Save BinaryGeometry/10823481 to your computer and use it in GitHub Desktop.
Passing Url Parameters from Magento Controller to Block view.If you
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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