1

I am getting the error in my custom admin module -

Fatal error: Call to a member function setRecipeProducts() on a non-object in C:\xampp\htdocs\sample\app\code\local\Sigmasolve\Recipe\controllers\Adminhtml\RecipeController.php on line 155

Sigmasolve_Recipe is my custom module name and here is the controller file:

public function _initRecipe()
{
    $this->loadLayout()
        ->_title($this->__('Product Grid'))
        ->renderLayout();
}
public function productsAction()
{
    $this->_initRecipe(); //if you don't have such a method then replace it with something that will get you the entity you are editing.
    $this->loadLayout();
    $this->getLayout()->getBlock('recipe.edit.tab.product')
        ->setRecipeProducts($this->getRequest()->getPost('recipe_products', null));
    $this->renderLayout();
}
public function productsgridAction()
{
    $this->_initRecipe();
    $this->loadLayout();
    $this->getLayout()->getBlock('recipe.edit.tab.product')
        ->setRecipeProducts($this->getRequest()->getPost('recipe_products', null));
    $this->renderLayout();
}


<?xml version="1.0"?>
<config>
    <modules>
        <Sigmasolve_Recipe>
            <version>1.0.0</version>
        </Sigmasolve_Recipe>
    </modules>
   <!--  <frontend>
        <routers>
            <recipe>
                <use>standard</use>
                <args>
                    <module>Sigmasolve_Recipe</module>
                    <frontName>recipe</frontName>
                </args>
            </recipe>
        </routers>
        <layout>
            <updates>
                <recipe>
                    <file>recipe.xml</file>
                </recipe>
            </updates>
        </layout>
    </frontend> -->
    <admin>
        <routers>
            <recipe>
                <use>admin</use>
                <args>
                    <module>Sigmasolve_Recipe</module>
                    <frontName>recipe</frontName>
                </args>
            </recipe>
        </routers>
    </admin>
    <adminhtml>
        <menu>
            <recipe module="recipe">
                <title>Recipe</title>
                <sort_order>71</sort_order>                
                <children>
                    <items module="recipe">
                        <title>Manage Recipe</title>
                        <sort_order>0</sort_order>
                        <action>recipe/adminhtml_recipe</action>
                    </items>
                </children>
            </recipe>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <recipe>
                            <title>Recipe Module</title>
                            <sort_order>200</sort_order>
                        </recipe>
                    </children>
                </admin>
            </resources>    
        </acl>
        <layout>
            <updates>
                <recipe>
                    <file>recipe.xml</file>
                </recipe>
            </updates>

        </layout>
    </adminhtml>    
    <global>
        <models>
            <recipe>
                <class>Sigmasolve_Recipe_Model</class>
                <resourceModel>recipe_mysql4</resourceModel>
            </recipe>
            <recipe_mysql4>
                <class>Sigmasolve_Recipe_Model_Mysql4</class>
                <entities>
                    <recipe>
                        <table>recipe</table>
                    </recipe>
                    <recipe_product>
                        <table>recipe_product</table>
                    </recipe_product>
                </entities>
            </recipe_mysql4>
        </models>
        <resources>
            <recipe_setup>
                <setup>
                    <module>Sigmasolve_Recipe</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </recipe_setup>
            <recipe_write>
                <connection>
                    <use>core_write</use>
                </connection>


            </recipe_write>
            <recipe_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </recipe_read>
        </resources>
        <blocks>
            <recipe>
                <class>Sigmasolve_Recipe_Block</class>
            </recipe>
        </blocks>
        <helpers>
            <recipe>
                <class>Sigmasolve_Recipe_Helper</class>
            </recipe>
        </helpers>
    </global>
</config>
2

Make sure you have in the layout file corresponding to your module this

<recipe_adminhtml_recipe_products>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="recipe/adminhtml_recipe_edit_tab_product" name="recipe.edit.tab.product"/>
        <block type="adminhtml/widget_grid_serializer" name="product_grid_serializer">
            <reference name="product_grid_serializer">
                <action method="initSerializerBlock">
                    <grid_block_name>recipe.edit.tab.product</grid_block_name>
                    <data_callback>getSelectedProducts</data_callback>
                    <hidden_input_name>products</hidden_input_name>
                    <reload_param_name>recipe_products</reload_param_name>
                </action>
                <action method="addColumnInputName">
                    <input_name>position</input_name>
                </action>
            </reference>
        </block>
    </block>
</recipe_adminhtml_recipe_products>
<recipe_adminhtml_recipe_productsgrid>
    <block type="core/text_list" name="root" output="toHtml">
        <block type="recipe/adminhtml_recipe_edit_tab_product" name="recipe.edit.tab.product"/>
</block>
</recipe_adminhtml_recipe_productsgrid>

Keep in mind that the layout handles adminhtml_sigmasolve_recipe_products and adminhtml_sigmasolve_recipe_productsgrid might be different depending on the url key your module has.
Also the block alias might be different. Instead of sigmasolve_recipe in sigmasolve_recipe/adminhtml_recipe_edit_tab_product you might need to put the tag name from under the <blocks> tag from your config.xml file.
But I see you followed this answer to create your many to many relation with the products, so chances are you are using the same notation as I did above. If, indeed, you followed that answer, make sure you did not miss a file and that you cleared the cache.

  • yes @Marius you are right i am followed that answer. I put layout file in "C:\xampp\htdocs\sample\app\design\adminhtml\default\default\layout" so is this right or not? – H_Parekh Dec 22 '16 at 10:11
  • yep, it's right – Marius Dec 22 '16 at 10:13
  • so i am try your answer but still get same error can you please help me out of this problem – H_Parekh Dec 22 '16 at 10:14
  • please add to your question the config.xml file of your module. – Marius Dec 22 '16 at 10:16
  • i added config.xml file in my question.. – H_Parekh Dec 22 '16 at 10:19
1

This error means that the following code:

$this->getLayout()->getBlock('recipe.edit.tab.product')

does not return an existing block.

You need to check your layout and the way this block is supposed to be added to your layout and fix it in order for your code to work. It could be as simple as a typo.

  • <block type="recipe/adminhtml_recipe_edit_tab_product" name="recipe.edit.tab.product"/> <block type="adminhtml/widget_grid_serializer" name="product_grid_serializer"> – H_Parekh Dec 22 '16 at 10:00
  • @H_Parekh yes ok but in which layout handle is that added ? – Raphael at Digital Pianism Dec 22 '16 at 10:04

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.