Mage_Core_Block_Abstract
/**
* Base Content Block class
*
* For block generation you must define Data source class, data source class method,
* parameters array and block template
*
* @category Mage
* @package Mage_Core
* @author Magento Core Team <core@magentocommerce.com>
*/
abstract class Mage_Core_Block_Abstract extends Varien_Object
{
抽象类。
1
变量。
const CACHE_GROUP = 'block_html';
//Block name in layout--->???what?,oh i know!在layout中block的名字。
protected $_nameInLayout;
//Parent layout of the block----->??????????????
@var Mage_Core_Model_Layout
protected $_layout;
//Parent block 父block
@var Mage_Core_Block_Abstract
protected $_parent;
//Short alias of this block to be refered from parent--别名
@var string
protected $_alias;
//Suffix for name of anonymous block,匿名block的下标
@var string
protected $_anonSuffix;
//Contains references to child block objects 包含子block objects的数组。
@var array
protected $_children = array();
//Sorted children list
@var array
protected $_sortedChildren = array();
//Sorted children list
@var array
protected $_sortedChildren = array();
//Children blocks HTML cache array
@var array
protected $_childrenHtmlCache = array();
//Arbitrary groups of child blocks
@var array
protected $_childGroups = array();
//Request object
@var Zend_Controller_Request_Http
protected $_request;
//Messages block instance 消息block实例
@var Mage_Core_Block_Messages
protected $_messagesBlock = null;
//Whether this block was not explicitly named
@var boolean
protected $_isAnonymous = false;
//*Parent block
@var Mage_Core_Block_Abstract
protected $_parentBlock;
//Block html frame open tag
@var string
protected $_frameOpenTag;
//Block html frame close tag
@var string
protected $_frameCloseTag;
protected static $_urlModel;
2
函数
2.1
//Retrieve request object
@return Mage_Core_Controller_Request_Http
public function getRequest()
2.2
//Retrieve parent block
@return Mage_Core_Block_Abstract
public function getParentBlock()
2.3
//Set parent block
@param Mage_Core_Block_Abstract $block
@return Mage_Core_Block_Abstract
public function setParentBlock(Mage_Core_Block_Abstract $block)
2.4
//Retrieve current action object
@return Mage_Core_Controller_Varien_Action
public function getAction()
2.5
//Set layout object
@param Mage_Core_Model_Layout $layout
@return Mage_Core_Block_Abstract
public function setLayout(Mage_Core_Model_Layout $layout)
2.6
//Preparing global layout
You can redefine this method in child classes for changin layout
@return Mage_Core_Block_Abstract
protected function _prepareLayout()
2.7
//Retrieve layout object得到layout objects
@return Mage_Core_Model_Layout
public function getLayout()
2.8
//Check if block is using auto generated (Anonymous) name是否是匿名。
@return bool
public function getIsAnonymous()
2.9
public function setIsAnonymous($flag)
2.10
public function getAnonSuffix()
public function setAnonSuffix($suffix)
2.11
public function getBlockAlias()
public function setBlockAlias($alias)
2.12
Set block's name in layout and unsets previous link if such exists.
@param $name
@return Mage_Core_Block_Abstract
public function setNameInLayout($name)
2.13
public function getSortedChildren()
2.14
//Set block attribute value
Wrapper for method "setData"
@param string $name
@param mixed $value
@return Mage_Core_Block_Abstract
public function setAttribute($name, $value=null)
2.15
Set child block
@param string $name
@param Mage_Core_Block_Abstract $block
@return Mage_Core_Block_Abstract
public function setChild($alias, $block)
2.16
Unset child block
@param string $name
@return Mage_Core_Block_Abstract
public function unsetChild($alias)
2.17
//Call a child and unset it, if callback matched result
public function unsetCallChild($alias, $callback, $result, $params)
2.18
//Unset all children blocks
@return Mage_Core_Block_Abstract
public function unsetChildren()
2.19
//Retrieve child block by name
@param string $name
@return mixed
public function getChild($name='')
2.20
//Retrieve child block HTML
@param string $name
@param boolean $useCache
@return string
public function getChildHtml($name='', $useCache=true, $sorted=false)
2.21
public function getChildChildHtml($name, $childName = '', $useCache = true, $sorted
= false)
2.22
//Obtain sorted child blocks
@return array------->这种情况应该应用于类似left,content等这样的类型的block块。
public function getSortedChildBlocks()
2.23
//Retrieve child block HTML ----> 子block html
@param string $name
@param boolean $useCache
@return string
protected function _getChildHtml($name, $useCache=true)
2.24
//Prepare child block before generate html
@param string $name
@param Mage_Core_Block_Abstract $child
在子block->html前进行的操作。
protected function _beforeChildToHtml($name, $child)
2.25
Retrieve block html
@param string $name
@return string
public function getBlockHtml($name)
2.26
Insert child block
随意插入!block,爽!!!!哈哈!人性化!
@param Mage_Core_Block_Abstract|string $block
@param string $siblingName
@param boolean $after
@param string $alias
@return object $this
public function insert($block, $siblingName='', $after=false, $alias='')
2.27
//Append child block
@param Mage_Core_Block_Abstract|string $block
@param string $alias
@return Mage_Core_Block_Abstract
public function append($block, $alias='')
2.28
//Make sure specified block will be registered in the specified child groups
@param string $groupName
@param Mage_Core_Block_Abstract $child
public function addToChildGroup($groupName, Mage_Core_Block_Abstract $child)
2.29
Add self to the specified group of parent block
@param string $groupName
@return Mage_Core_Block_Abstract
public function addToParentGroup($groupName)
3.30
Get a group of child blocks
@param string $groupName
@param string $callback
@param bool $skipEmptyResults
@return array
public function getChildGroup($groupName, $callback = null, $skipEmptyResults =
true)
3.31
Get a value from child block by specified key
@param string $alias
@param string $key
@return mixed
public function getChildData($alias, $key = '')
3.31
Before rendering html, but after trying to load cache
@return Mage_Core_Block_Abstract
protected function _beforeToHtml()
3.32
Specify block output frame tags
@param $openTag
@param $closeTag
@return Mage_Core_Block_Abstract
public function setFrameTags($openTag, $closeTag=null)
3.33
Specify block output frame tags
@param $openTag
@param $closeTag
@return Mage_Core_Block_Abstract
public function setFrameTags($openTag, $closeTag=null)
3.34
//Produce and return block's html output
It is a final method, but you can override _toHmtl() method in descendants if needed
@return string
final public function toHtml()
3.35
Processing block html after rendering
@param string $html
@return string
protected function _afterToHtml($html)
3.36
//Override this method in descendants to produce html
@return string
protected function _toHtml()
3.37
@return string
protected function _getUrlModelClass()
3.38
protected function _getUrlModel()
3.39
* Generate url by route and parameters
3.40
Generate url by route and parameters
@param string $route
@param array $params
@return string
public function getUrl($route='', $params=array())
3.41
Generate base64-encoded url by route and parameters
@param string $route
@param array $params
@return string
public function getUrlBase64($route='', $params=array())
3.42
Generate url-encoded url by route and parameters
@param string $route
@param array $params
@return string
public function getUrlEncoded($route = '', $params = array())
3.43
Retrieve url of skins file
@param string $file path to file in skin
@param array $params
@return string
public function getSkinUrl($file=null, array $params=array())
3.44
Retrieve messages block
@return Mage_Core_Block_Messages
public function getMessagesBlock()
3.45
Set messages block
@param Mage_Core_Block_Messages $block
@return Mage_Core_Block_Abstract
public function setMessagesBlock(Mage_Core_Block_Messages $block)
3.46
@param string $type
@return Mage_Core_Block_Abstract
public function getHelper($type)
3.47
Retrieve formating date
@param string $date
@param string $format
@param bool $showTime
@return string
public function formatDate($date=null, $format='short', $showTime=false)
3.48
Retrieve formating time
@param string $time
@param string $format
@param bool $showDate
@return string
public function formatTime($time=null, $format='short', $showDate=false)
3.49
//Retrieve module name of block
@return string
public function getModuleName()
3.50
Translate block sentence
@return string
public function __()
3.51
@deprecated after 1.4.0.0-rc1
@see self::escapeHtml()
public function htmlEscape($data, $allowedTags = null)
3.52
Escape html entities
@param mixed $data
@param array $allowedTags
@return string
public function escapeHtml($data, $allowedTags = null)
3.53
Escape html entities in url
@param string $data
@return string
public function escapeUrl($data)
3.54
Escape quotes in java scripts
@param mixed $data
@param string $quote
@return mixed
public function jsQuoteEscape($data, $quote = '/'')
3.55
Alias for getName method.
@return string
public function getNameInLayout()
3.56
Get chilren blocks count
@return int
public function countChildren()
3.57
Prepare url for save to cache
@return Mage_Core_Block_Abstract
protected function _beforeCacheUrl()
3.58
Replace URLs from cache
@param string $html
@return string
protected function _afterCacheUrl($html)
3.59
Get cache key informative items
Provide string array key to share specific info item with FPC placeholder
@return array
public function getCacheKeyInfo()
3.60
Get Key for caching block content
@return string
public function getCacheKey()
3.61
Get tags array for saving cache
@return array
public function getCacheTags()
3.62
//Get block cache life time
@return int
public function getCacheLifetime()
3.63
//Get block cache life time
@return int
public function getCacheLifetime()
3.64
Load block html from cache storage
@return string | false
protected function _loadCache()
3.65
Save block content to cache storage
@param string $data
@return Mage_Core_Block_Abstract
protected function _saveCache($data)