在Magento 1.5中,我看到它使用了$this-> getchildhood(),这是怎么回事?我现在知道我们不能在PHP中重新赋值$this。我想定义的方法,可以访问$this通过我的项目,就像Magento。
Magento中的php文件可以使用这个,因为它们是由block的_toHtml
方法渲染的
//simplified version
protected function _toHtml()
{
include('path/to/template.phtml')
}
protected _someMethod()
{
return 'some thing';
}
,然后在模板
#File: path/to/template.phtml
<h1><?php $this->_someMethod(); ?></h1>
如果你想定义你自己的方法,你需要定义你自己的块类,并使用这些块类来添加php模板的布局。