1
I am trying to display random testimonials, but due to magento cache the random is not working, i have to flush the cache each time to see the testimonials change, my code

 public function getTestimonialsLast(){
        $collection = Mage::getModel('testimonial/testimonial')->getCollection();
        $collection->getSelect()->order(new Zend_Db_Expr('RAND()'));
        $collection->addFieldToFilter('status',1);
        $collection->setPageSize(5);
        return $collection;
    }

how can i make it work , how can i make it so that whenever the page is refreshed the collection is randomized. Any help is greatly appreciated. Thank you in advance,

4

2 回答 2

2

一种可能性是在视图文件中:

您可以通过在实现块时添加false参数来阻止 Magento 缓存块。

<?php echo $this->getChildHtml('testimonials', false) ?>

因为

Method Summary 
string getChildHtml ([string $name = ‘’], [boolean $useCache = true], [ $sorted = true])

或者您可以将缓存生命周期添加到您的推荐类:

public function getCacheLifetime() { return null; }
于 2013-08-02T19:19:22.003 回答
0

您是否在模块公共函数 __construct() 中缓存块

它会有关于“cache_lifetime”的信息

删除缓存块将阻止它被缓存并每次执行新的调用。

于 2013-08-02T18:02:42.730 回答