magento如何调用此方法
我正在学习Magento,我遇到了这个问题 模板文件代码magento如何调用此方法,magento,Magento,我正在学习Magento,我遇到了这个问题 模板文件代码 <?php $testimonials = $this->getTestimonials(); ?> <?php $i = 0;?> <?php if ($testimonials->count() > 0): ?> <div class="block testimonials_sidebar"> <div class="block-title">
<?php $testimonials = $this->getTestimonials(); ?>
<?php $i = 0;?>
<?php if ($testimonials->count() > 0): ?>
<div class="block testimonials_sidebar">
<div class="block-title">
<strong><span><?php echo $this->__('Testimonials') ?></span></strong>
</div>
<div class="block-content">
<?php foreach ($testimonials as $testimonial): ?>
<div class="testimonial_sidebar_box">
<div class="testimonial_sidebar_text"><?php echo $testimonial->getTestimonialText(); ?></div>
<div class="testimonial_sidebar_name"><?php echo $testimonial->getTestimonialName(); ?></div>
</div>
<?php endforeach; ?>
<div class="actions">
<a href="<?php echo $this->getUrl('testimonials'); ?>"><?php echo $this->__('View All Testimonials'); ?></a>
</div>
</div>
</div>
<?php endif;?>
如果我按ctrl键,在模板文件中单击该方法,它将带我到注释中的该方法。我可以看到它指向收藏,所以这里是我的收藏代码
class Turnkeye_Testimonial_Model_Mysql4_Testimonial_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
/**
* Initialization here
*
*/
public function _construct()
{
parent::_construct();
$this->_init('turnkeye_testimonial/testimonial');
}
}请参见-Magento中所谓的magic Getter和Setter的基础。Magento makes使用magic
\u call()
方法为Magento对象中的私有(隐藏)数据动态“创建”访问器方法
Magento中的大多数类继承自Varien\u对象
,其中定义了magic\u call()
方法
如果您想了解有关PHP中的magic\uu call()
函数的更多信息,可以在此处阅读:
其他神奇的方法可以在这里找到:。(类似于\uuu call()
的是神奇的方法\uu get()
和\uu set()
)
我发现一篇文章解释了这一切在Magento中的工作原理:
您看到的以@method
开头的注释行是对文档生成器、IDE和您的一个提示,即虽然此方法未在代码中定义,但它应该可以通过magic\u call()
方法访问。如果您使用的是Netbeans或Eclipse之类的IDE,那么应该为该方法完成代码
/**
* Frontend block for testimonials
*
* @method Turnkeye_Testimonial_Model_Mysql4_Testimonial_Collection getTestimonials()
*/
class Turnkeye_Testimonial_Block_Testimonial extends Mage_Core_Block_Template
{
/**
* Before rendering html, but after trying to load cache
*
* @return Turnkeye_Testimonial_Block_Testimonial
*/
protected function _beforeToHtml()
{
$this->_prepareCollection();
return parent::_beforeToHtml();
}
/**
* Prepare testimonial collection object
*
* @return Turnkeye_Testimonial_Block_Testimonial
*/
protected function _prepareCollection()
{
/* @var $collection Turnkeye_Testimonial_Model_Mysql4_Testimonial_Collection */
$collection = Mage::getModel("turnkeye_testimonial/testimonial")->getCollection();
if ($this->getSidebar()){
$collection->addFieldToFilter('testimonial_sidebar', '1');
}
$collection->setOrder('testimonial_position', 'ASC')
->load();
$this->setTestimonials($collection);
return $this;
}
}
class Turnkeye_Testimonial_Model_Mysql4_Testimonial_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
/**
* Initialization here
*
*/
public function _construct()
{
parent::_construct();
$this->_init('turnkeye_testimonial/testimonial');
}