0

I am trying to call getProducts method from content.phtml file.

Block file:

class AdminModules_Topjob_Block_Topjob extends Mage_Core_Block_Template
   {
        public function getProducts($pro_cond, $terminal_block)
        {
           $model = Mage::getModel('topjob/topjob');
           return $model->getProductsByCond($pro_cond, $terminal_block);
        }
   }

Content.phtml :

$myProducts = $this->getProducts('24 - 16 AWG', '2-CONDUCTOR TERMINAL BLOCKS');

Layout file:

<?xml version="1.0"?>
<layout version="0.1.1">
    <topjob_index_index>
        <reference name="content">
            <block type="topjob/content" name="topjob" template="topjob/content.phtml" />
        </reference>
    </topjob_index_index>
</layout>

Error:

Invalid method Mage_Core_Block_Template::getProducts(Array
(
    [0] => 24 - 16 AWG
    [1] => 2-CONDUCTOR TERMINAL BLOCKS
)
)

Trace:
#0 /home/usauto/public_html/app/design/frontend/b-responsive/default/template/topjob/content.phtml(90): Varien_Object->__call('getProducts', Array)
#1 /home/usauto/public_html/app/design/frontend/b-responsive/default/template/topjob/content.phtml(90): Mage_Core_Block_Template->getProducts('24 - 16 AWG', '2-CONDUCTOR TER...')
#2 /home/usauto/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/usauto/pu...')
#3 /home/usauto/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/b-resp...')
#4 /home/usauto/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#5 /home/usauto/public_html/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml()
#6 /home/usauto/public_html/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#7 /home/usauto/public_html/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml()
#8 /home/usauto/public_html/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml()
#9 /home/usauto/public_html/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#10 /home/usauto/public_html/app/design/frontend/b-responsive/default/template/page/1column.phtml(56): Mage_Core_Block_Abstract->getChildHtml('content')
#11 /home/usauto/public_html/app/code/core/Mage/Core/Block/Template.php(241): include('/home/usauto/pu...')
#12 /home/usauto/public_html/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/b-resp...')
#13 /home/usauto/public_html/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#14 /home/usauto/public_html/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml()
#15 /home/usauto/public_html/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#16 /home/usauto/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#17 /home/usauto/public_html/app/code/local/AdminModules/Topjob/controllers/IndexController.php(16): Mage_Core_Controller_Varien_Action->renderLayout()
#18 /home/usauto/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): AdminModules_Topjob_IndexController->indexAction()
#19 /home/usauto/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#20 /home/usauto/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#21 /home/usauto/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#22 /home/usauto/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#23 /home/usauto/public_html/index.php(89): Mage::run('', 'store')
#24 {main}
0
<block type="topjob/content" name="topjob" template="topjob/content.phtml" />

It should be

<block type="topjob/topjob" name="topjob" template="topjob/content.phtml" />

and your config.xml should have this under the <global> tag

<blocks>
     <topjob>
        <class>AdminModules_Topjob_Block</class>
     </topjob>
</blocks>
1
  • Thank you for your answer, <blocks> tag is there under <global> tag. Also tried changing the block type, still not working – Sayali Oct 14 '16 at 15:29
0

In your layout file I would do :

<?xml version="1.0"?>
<layout version="0.1.1">
    <topjob_index_index>
        <reference name="content">
            <block type="adminmodules_topjob/topjob" name="topjob" template="topjob/content.phtml" />
        </reference>
    </topjob_index_index>
</layout>

Then flush your cache. My guess is that your block type is wrong.

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.