Question

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,

Était-ce utile?

La solution

One possibility is in the view file:

You can stop Magento from caching the block by adding a false parameter when you implement the block.

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

Because of

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

Or you could add the cache lifetime to your testimonial class:

public function getCacheLifetime() { return null; }

Autres conseils

Are you caching the block within the modules public function __construct()

It would have information on 'cache_lifetime'

Removing the cache block would prevent it from being cached and perform a fresh call each time.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top