Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3355030
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:20:45+00:00 2026-05-18T02:20:45+00:00

I am working on a custom admin module where I show a list of

  • 0

I am working on a custom admin module where I show a list of customers based on a custom attribute, the grid loads fine but then I am having problems whenever I try to sort/filter the grid.

This is the error I am getting :

Fatal error:  Call to a member function toHtml() on a non-object in <b>/***/***/public_html/***/app/code/local/BelVG/Events/controllers/CodesController.php</b> on line <b>28</b>

This is the code that causes the error in the CodesController file :

public function customerGridAction() {
    $this->loadLayout();
    $this->getResponse()->setBody($this->getLayout()->getBlock('events.codes.edit.customer')->toHtml());
}

XML layout file:

<events_codes_edit>
    <reference name="content">
        <block type="events/codes_edit" name="events.codes.edit" template="events/codes/edit.phtml">
        <block type="events/codes_edit_customer" name="events.codes.edit.customer" as="customer"/>
         </block>
    </reference>
</events_codes_edit>

<events_codes_edit_customergrid>
    <remove name="root"/>
    <block type="events/codes_edit_customer" name="events.codes.edit.customer" as="events.codes.edit.customer"/>
</events_codes_edit_customergrid></code>

Class file for the Grid:

class BelVG_Events_Block_Codes_Edit_Customer extends Mage_Adminhtml_Block_Widget_Grid
{

public function __construct() {
    parent::__construct();
    $this->setId('events_codes_edit_product');
    $this->setUseAjax(true);
    $this->setDefaultSort('entity_id');
    $this->setDefaultDir('asc');
    $this->setSaveParametersInSession(true);
}

protected function _prepareCollection()
{
    $current_code = Mage::registry('current_code');
    $code = $current_code->getCode();
    $collection = Mage::getResourceModel('customer/customer_collection')
        ->addNameToSelect()
        ->addAttributeToSelect('email')
        ->addAttributeToSelect('i_code')
        ->addAttributeToSelect('gender')
        ->addFieldToFilter('i_code', $code)
        ->joinAttribute('billing_postcode', 'customer_address/postcode', 'default_billing', null, 'left')
        ->joinAttribute('billing_city', 'customer_address/city', 'default_billing', null, 'left')
        ->joinAttribute('billing_telephone', 'customer_address/telephone', 'default_billing', null, 'left')
        ->joinAttribute('billing_region', 'customer_address/region', 'default_billing', null, 'left')
        ->joinAttribute('billing_country_id', 'customer_address/country_id', 'default_billing', null, 'left');

    $this->setCollection($collection);

    return parent::_prepareCollection();
}

 protected function _prepareColumns() {
    $this->addColumn('entity_id', array(
        'header'    => Mage::helper('customer')->__('ID'),
        'width'     => '50px',
        'index'     => 'entity_id',            
        'type'  => 'number'
    ));
    $this->addColumn('name', array(
        'header'    => Mage::helper('customer')->__('Name'),
        'index'     => 'name'
    ));
    $this->addColumn('email', array(
        'header'    => Mage::helper('customer')->__('Email'),
        'width'     => '150',
        'index'     => 'email'
    ));
    $this->addColumn('Telephone', array(
        'header'    => Mage::helper('customer')->__('Telephone'),
        'width'     => '100',
        'index'     => 'billing_telephone'
    ));

    $this->addColumn('billing_postcode', array(
        'header'    => Mage::helper('customer')->__('ZIP'),
        'width'     => '90',
        'index'     => 'billing_postcode'
    ));

    $this->addColumn('billing_country_id', array(
        'header'    => Mage::helper('customer')->__('Country'),
        'width'     => '100',
        'index'     => 'billing_country_id'
    ));

    $this->addColumn('billing_region', array(
        'header'    => Mage::helper('customer')->__('State/Province'),
        'width'     => '100',
        'index'     => 'billing_region'
    ));

    $this->addColumn('gender', array(
        'header'    => Mage::helper('customer')->__('Gender'),
        'align'     => 'center',
        'index'     => 'gender'
    ));


    return parent::_prepareColumns();
}

public function getGridUrl() {
    return $this->getUrl('*/*/customergrid', array('_current'=> true));
}

}

This grid is first called inside another block, which is Edit.php, and it’s called from a template file edit.phtml

Edit.php block class:

class BelVG_Events_Block_Codes_Edit extends Mage_Core_Block_Template {

    public function getGridHtml() {
        return $this->getChild('customer')->toHtml();
    }

}

Code for calling the customer grid inside edit.phtml:

<div id="" class="fieldset">
        <div class="hor-scroll">
            <?php echo $this->getGridHtml() ?>
        </div>
</div>

I have no idea why this is happening, I have double checked the block name in the controller, and the layout files and they seem to be matching, I even tried to use createBlock() instead of getBlock() and pointed directly to the block file, but still it showed the exact same error.

Can anyone point me in the right direction?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T02:20:46+00:00Added an answer on May 18, 2026 at 2:20 am

    I am not sure what your module/controller/action path looks like, but I would say that you have made something wrong in your xml at:

    <events_codes_edit_customergrid>
    

    I am guessing this should say

    <events_codes_customergrid>
    

    But anyhow. this is not really required if you want to get the html for one particular block. What I recommend doing is, use the layout class to create the block and then show it.

    This usually works for all grid blocks, as they have the Collection instance defined inside the class.

    so try using

    $this->getResponse()->setBody($this->getLayout()->createBlock('events/codes_edit_customer')->toHtml());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I often find linq being problematic when working with custom collection object. They are
In some instances, I prefer working with custom objects instead of strongly typed datasets
I'm working on a custom CMS for my own use and was thinking about
I'm working on a custom mark-release style memory allocator for the D programming language
As I'm working to add custom printing to my application, I've settled on using
I can't seem to get a custom action working. I might be doing this
I'm working on an RSS feed for a custom tasking system we use, and
I am working on localization for an app where custom patterns are used to
I am working on a Windows utility program which communicates with some custom hardware
I'm working on the development of a C++ API which uses custom-designed plugins to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.