문제

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;
   }
}
도움이 되었습니까?

해결책

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')
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top