I am trying to access a class's method using Mage::getSingleton()

I have done the following:

<?php $allReviews = Mage::getSingleton('efkreports/product_allReviews')->getAllProductReviews(); ?>
<?php zend_debug::dump($allReviews); ?>

But this is giving me error:

Fatal error: Call to a member function getAllProductReviews() on a non-object in C:\xampp\htdocs\efk\app\design\frontend\default\efk1\template\catalog\product\list\related.phtml on line 37

I even tried using:

<?php $allReviews = $this->Mage::getSingleton('efkreports/product_allReviews')->getAllProductReviews(); ?>

which is giving me same error..

Please help me in how to call a method through a class name..





//This class is for getting Best selling products list
class Efk_Reports_Block_Product_AllReviews extends Mage_Reports_Block_Product_Abstract
   public function getAllProductReviews(){
        //some calculations here

        return $_productCollection;
  • Are you sure the class exists? Can you post the config.xml of the module and the allReviews class (at least its path on the disk) – Marius Nov 19 '13 at 10:29
  • @Marius updated.. – Mr_Green Nov 19 '13 at 10:32
  • @Marius Does what I am doing here should work in normal cases? – Mr_Green Nov 19 '13 at 10:46

Mage::getSingleton creates an instance of a model and returns it as a singleton. You are trying to work with a block. For this try:



| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.