私はMagentoを学んでいますが、この問題に遭遇しました。
テンプレート ファイル コード
<?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;?>
テンプレートファイルのコードの最初の行を確認するためにブロックに移動すると、
<?php $testimonials = $this->getTestimonials(); ?>
そして、そのブロッククラスで宣言されたこのメソッドを見つけることができませんでした。代わりに、このメソッドをコメントセクションで見ることができます。しかし、このメソッドはモジュールのどこにも宣言されていません。これはどのように起こっていますか?以下のブロッククラスコード。
/**
* 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;
}
}
テンプレートファイルでそのメソッドを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');
}
}