2

I know, it's been asked a lot but it just doesn't work for me.

my config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <MyModule_CatalogSearch>
      <version>0.0.1</version>
    </MyModule_CatalogSearch>
  </modules>

  <global>
    <blocks>
      <MyModule_CatalogSearch>
        <class>MyModule_CatalogSearch_Block</class>
      </MyModule_CatalogSearch>
      <catalogsearch>
        <rewrite>
            <advanced_form>
                MyModule_CatalogSearch_Block_Advanced_Form
            </advanced_form>
        </rewrite>
      </catalogsearch>
    </blocks>
  </global>
</config>

and in local/MyModule/CatalogSearch/Block/Advanced I got Form.php

<?php
class MyModule_CatalogSearch_Block_Advanced_Form extends Mage_CatalogSearch_Block_Advanced_Form
{
    public function _prepareLayout()
    {
        // add Home breadcrumb
        if ($breadcrumbs = $this->getLayout()->getBlock('breadcrumbs')) {
            $breadcrumbs->addCrumb('home', array(
                'label'=>Mage::helper('catalogsearch')->__('Home'),
                'title'=>Mage::helper('catalogsearch')->__('Go to Home Page'),
                'link'=>Mage::getBaseUrl()
            ))->addCrumb('search', array(
                'label'=>Mage::helper('catalogsearch')->__('MyCatalogSearch')
            ));
        }
        return parent::_prepareLayout();
    }

     public function getStoreCategories()
    {
        $helper = Mage::helper('catalog/category');
        return $helper->getStoreCategories();
    }
}

In exception.log I get the following: Invalid block type2:

                MyModule_CatalogSearch_Block_Advanced_Form
            #0 //app/code/core/Mage/Core/Model/Layout.php(495): Mage->throwException('Invalid block type2: 
                MyModule_CatalogSearch_Block_Advanced_Form
            ')
#1 //app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('catalogsearch/advanced_form', Array)
#2 //app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('catalogsearch/advanced_form', 'catalogsearch_advanced_form')
#3 //app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('catalogsearch/advanced_form', 'catalogsearch_advanced_form')
#4 //app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Mage_Core_Model_Layout_Element, Mage_Core_Model_Layout_Element)
#5 //app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Mage_Core_Model_Layout_Element)
#6 //app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#7 //app/code/core/Mage/Core/Controller/Varien/Action.php(269): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#8 //app/code/core/Mage/CatalogSearch/controllers/AdvancedController.php(39): Mage_Core_Controller_Varien_Action->loadLayout()
#9 //app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_CatalogSearch_AdvancedController->indexAction()
#10 //app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#11 //app/code/community/ArtsOnIT/OfflineMaintenance/Controller/Router/Standard.php(46): Mage_Core_Controller_Varien_Router_Standard->match(Mage_Core_Controller_Request_Http)
#12 //app/code/core/Mage/Core/Controller/Varien/Front.php(172): ArtsOnIT_OfflineMaintenance_Controller_Router_Standard->match(Mage_Core_Controller_Request_Http)
#13 /app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#14 //app/Mage.php(675): Mage_Core_Model_App->run(Array)
#15 /4/magento/index.php(87): Mage->run('', 'store')

I changed Layout.php to see where there exception is thrown and it happens in

if (!$block instanceof Mage_Core_Block_Abstract) {
            Mage::throwException(Mage::helper('core')->__('Invalid block type2: %s', $block));
        }

Can someone explain WHY this happens and how to fix it?

Thanks a lot

Solution: There were spaces before the class name. Removing them as suggested by Amit solved it.

2
<MyModule_CatalogSearch>
<class>MyModule_CatalogSearch_Block</class>
</MyModule_CatalogSearch>

change to

<mymodulecatalogsearch>
<class>MyModule_CatalogSearch_Block</class>
</mymodulecatalogsearch>

Explain:

here <MyModule_CatalogSearch> is a block typeand it is always be lower letters.

Block type is always be small letter.As we define block type is <mymodulecatalogsearch> then it class MyModule_CatalogSearch_Block

config.xml

   <?xml version="1.0"?>
<config>
  <modules>
    <MyModule_CatalogSearch>
      <version>0.0.1</version>
    </MyModule_CatalogSearch>
  </modules>

  <global>
    <blocks>
     <mymodulecatalogsearch>
        <class>MyModule_CatalogSearch_Block</class>
    </mymodulecatalogsearch>
      <catalogsearch>
        <rewrite>
            <advanced_form>MyModule_CatalogSearch_Block_Advanced_Form</advanced_form>
        </rewrite>
      </catalogsearch>
    </blocks>
  </global>
</config>
  • Hi, thanks for your answer. I changed it but the same exception is still being thrown. On a cms block I'm adding a block using {{block type="MyModule_CatalogSearch/block" name="filter_result" }} which happens to work just fine – kilsen Sep 6 '14 at 15:19
  • {{block type="mymodulecatalogsearch/block" name="filter_result" }} AS mymodulecatalogsearch as block type of module MyModule_CatalogSearch – Amit Bera Sep 6 '14 at 15:21
  • im sure this would work as well but this didn't fix my actual problem – kilsen Sep 6 '14 at 15:23
  • which problem ? – Amit Bera Sep 6 '14 at 15:23
  • that the exception is being thrown i described in my original post when I call /catalogsearch/advanced. In my comment I just wanted to say that adding a block on a category page using this name works fine. – kilsen Sep 6 '14 at 15:29
1

Can you check your file in which you've got the class:

Mage_CatalogSearch_Block_Advanced_Form

You might have an accidental change in it. Check to see if the above class inherits from Mage_Core_Block_Abstract or on of it's child classes.

  • I posted the file in my original Post. It inherits from Mage_CatalogSearch_Block_Advanced_Form, – kilsen Sep 6 '14 at 15:31
  • Mage_CatalogSearch_Block_Advanced_Form should inherit from Mage_Core_Block_Abstract or one of it's child classes. Check that. – Paras Sood Sep 6 '14 at 15:32

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.