Created
January 21, 2014 19:13
-
-
Save xcommerce-gists/8546317 to your computer and use it in GitHub Desktop.
Sample Magento block for an individual news article
This file contains 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
<?php | |
/** | |
* News Item block | |
* | |
* @author Magento | |
*/ | |
class Magentostudy_News_Block_Item extends Mage_Core_Block_Template | |
{ | |
/** | |
* Current news item instance | |
* | |
* @var Magentostudy_News_Model_News | |
*/ | |
protected $_item; | |
/** | |
* Return parameters for back url | |
* | |
* @param array $additionalParams | |
* @return array | |
*/ | |
protected function _getBackUrlQueryParams($additionalParams = array()) | |
{ | |
return array_merge(array('p' => $this->getPage()), $additionalParams); | |
} | |
/** | |
* Return URL to the news list page | |
* | |
* @return string | |
*/ | |
public function getBackUrl() | |
{ | |
return $this->getUrl('*/', array('_query' => $this->_getBackUrlQueryParams())); | |
} | |
/** | |
* Return URL for resized News Item image | |
* | |
* @param Magentostudy_News_Model_News $item | |
* @param integer $width | |
* @return string|false | |
*/ | |
public function getImageUrl($item, $width) | |
{ | |
return Mage::helper('magentostudy_news/image')->resize($item, $width); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment