0

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..

EDIT:

Config.xml

<config>
    <modules>
        <Efk_Reports>
            <version>1.0.0.0</version>
        </Efk_Reports>
    </modules>
    <global>        
        <blocks>
            <efkreports>
                <class>Efk_Reports_Block</class>
            </efkreports>
        </blocks>
    </global>    
</config>

Class

//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
1

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:

Mage::app()->getLayout()->createBlock('efkreports/product_allReviews')

or

Mage::getBlockSingleton('efkreports/product_allReviews')
| 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.