0

I'm trying to write a module to display on my product page, but can't for the life of me get the initial blocks to display. Here's what I have so far:

app/code/local/Eden/Finance/etc/config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <Eden_Finance>
      <version>1.0.2</version>
    </Eden_Finance>
  </modules>
  <frontend>
    <routers>
      <finance>
        <use>standard</use>
        <args>
          <module>Eden_Finance</module>
          <frontName>finance</frontName>
        </args>
      </finance>
    </routers>
  </frontend>
  <layout>
  <updates>
    <finance>
      <file>finance.xml</file>
    </finance>
  </updates>
  </layout>
  <global>
    <helpers>
      <finance>
        <class>Eden_Finance_Helper</class>
      </finance>
    </helpers>
    <blocks>
      <finance>
        <class>Eden_Finance_Block</class>
      </finance>
    </blocks>
  </global>
</config>

app/code/local/Eden/Finance/controllers/IndexController.php:

<?php class Eden_Finance_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
        $this->loadLayout();
        $this->renderLayout();
    }

}

app/code/local/Eden/Finance/Blocks/Finance.php:

<?php class Eden_Finance_Block_Finance extends Mage_Core_Block_Template
{
    public function methodblock()
    {
        return 'test!';
     }


}

app/design/frontend/eden/default/layout/finance.xml:

<layout version="0.1.0">
    <default>
        <reference name="content">
        </reference>
    </default>
    <finance_index_index>
        <reference name="content">
            <block type="finance/finance" name="finance" as="finance" template="finance/init.phtml" />
        </reference>
    </finance_index_index>
    <finance_ajax_ajax>
        <remove name="right"/>
        <remove name="left"/>
        <block type="finance/finance" name="finance_ajax" as="finance_ajax" template="finance/ajax.phtml" output="toHtml" />
    </finance_ajax_ajax>
</layout>

(init.phtml and ajax.phtml are set up inside app/design/frontend/eden/default/template/finance/)

In the catalog.xml file I've included the following:

<block type="finance/finance" output="toHtml" name="finance" template="finance/init.phtml"/>

and then finally included <?php echo $this->getChildHtml('finance');?> inside my view.phtml page. This gives me the following errors in my exception.log file:

2018-06-20T12:56:24+00:00 ERR (3): 
Mage_Core_Exception: Invalid block type: Eden_Finance_Block_Finance in C:\wamp\www\eden\tmp\app\Mage.php:595
Stack trace:
#0 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\Layout.php(495): Mage::throwException('Invalid block t...')
#1 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('Eden_Finance_Bl...', Array)
#2 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\Layout.php(472): Mage_Core_Model_Layout->createBlock('finance/finance', 'finance')
#3 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\Layout.php(239): Mage_Core_Model_Layout->addBlock('finance/finance', 'finance')
#4 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#5 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\Layout.php(206): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#7 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Controller\Varien\Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#8 C:\wamp\www\eden\tmp\app\code\core\Mage\Catalog\Helper\Product\View.php(73): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#9 C:\wamp\www\eden\tmp\app\code\core\Mage\Catalog\Helper\Product\View.php(144): Mage_Catalog_Helper_Product_View->initProductLayout(Object(Mage_Catalog_Model_Product), Object(Mage_Catalog_ProductController))
#10 C:\wamp\www\eden\tmp\app\code\core\Mage\Catalog\controllers\ProductController.php(132): Mage_Catalog_Helper_Product_View->prepareAndRender(14570, Object(Mage_Catalog_ProductController), Object(Varien_Object))
#11 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Controller\Varien\Action.php(418): Mage_Catalog_ProductController->viewAction()
#12 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Controller\Varien\Router\Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('view')
#13 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Controller\Varien\Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#14 C:\wamp\www\eden\tmp\app\code\core\Mage\Core\Model\App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#15 C:\wamp\www\eden\tmp\app\Mage.php(683): Mage_Core_Model_App->run(Array)
#16 C:\wamp\www\eden\tmp\index.php(83): Mage::run('', 'store')
#17 {main}

It seems that my block type is invalid. Although when I change the catalog.xml entry to core/template instead, it works - but unfortunately, provides me no access to my Block and Helper functions. Is anybody able to guide me the right way to see what I'm doing wrong?

  • you created your block class as well ? – Pankaj Pareek Jun 20 '18 at 13:13
  • Sorry, yes I have. I've updated my question :) – Liam McArthur Jun 20 '18 at 13:16
  • then you have to change block type to type="eden/finance" in your XML file – Abhishek Panchal Jun 20 '18 at 13:18
  • @AbhishekPanchal then I get Mage_Core_Exception: Invalid block type: Mage_Eden_Block_Finance in C:\wamp\www\eden\tmp\app\Mage.php:595 – Liam McArthur Jun 20 '18 at 13:21
  • 1
    Can you confirm your block file is at path app/code/local/Eden/Finance/Blocks/Finance.php as there is an extra 's' in Block directory name (Blocks should be Block) – Piyush Jun 20 '18 at 13:23
0

app/code/local/Eden/Finance/Block/Finance.php

<?php
class Eden_Finance_Block_Finance extends Mage_Core_Block_Template
{

}

app/design/frontend/eden/default/layout/finance.xml

<layout version="0.1.0">
    <default>
        <reference name="content">
        </reference>
    </default>
    <finance_index_index>
        <reference name="content">
            <block type="finance/finance" name="finance" as="finance" template="finance/init.phtml" />
        </reference>
    </finance_index_index>
    <finance_ajax_ajax>
        <remove name="right"/>
        <remove name="left"/>
        <block type="finance/finance" name="finance_ajax" as="finance_ajax" template="finance/ajax.phtml" output="toHtml" />
    </finance_ajax_ajax>
</layout>
0

You can also used another way to call your file. Put below code into view.phtml

<?php echo $this->getLayout()->createBlock('finance/finance')->setTemplate('finance/init.phtml')->toHtml(); ?>

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.