magento customer module add new table and config show error "Fatal error: Call to a member function addFieldToFilter() on a non-object" in admin page

I Create a new table with the name of "directory_country_city",then i config the new table in my config.xml its placed in "FederalLawyer/app/code/local/Federallawyer/Customer/config.xml"

The code in config.xml
----------------------
<config>
    <modules>
        <Federallawyer_Customer>
            <version>1.1.5</version>
        </Federallawyer_Customer>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <customer_edit_tabs>Federallawyer_Customer_Block_Adminhtml_Customer_Edit_Tabs</customer_edit_tabs>
                    <customer_grid>Federallawyer_Customer_Block_Adminhtml_Customer_Grid</customer_grid>
                    <customer_edit_tab_account>Federallawyer_Customer_Block_Adminhtml_Customer_Edit_Tab_Account</customer_edit_tab_account>
                </rewrite>
            </adminhtml>
            <customer>
                <rewrite>
                    <form_register>Federallawyer_Customer_Block_Form_Register</form_register>
                    <account_navigation>Federallawyer_Customer_Block_Customer_Account_Navigation</account_navigation>
                    <address_book>Federallawyer_Customer_Block_Address_Book</address_book>
                    <form_edit>Federallawyer_Customer_Block_Form_Edit</form_edit>
                </rewrite>
            </customer>

            <federallawyer_customer>
                <class>Federallawyer_Customer_Block</class>
            </federallawyer_customer>

        </blocks>
        <helpers>
            <customer>
                <rewrite>
                    <data>Federallawyer_Customer_Helper_Data</data>
                </rewrite>
            </customer>
        </helpers>

        <models>
            <customer>
                <rewrite>
                    <customer>Federallawyer_Customer_Model_Customer</customer>
                </rewrite>
            </customer>
            <customer>
                <class>Federallawyer_Customer_Model</class>
                <resourceModel>customer_resource</resourceModel>
            </customer>
            <customer_resource>
                <class>Federallawyer_Customer_Model_Resource</class>
                <entities>
                    <cities><table>directory_country_city</table></cities>
                </entities>
            </customer_resource>

        </models>

          <resources>
            <federallawyer_customer_setup>
                <setup>
                    <module>Federallawyer_Customer</module>
                    <class>Mage_Customer_Model_Resource_Setup</class>
                </setup>
            </federallawyer_customer_setup>
        </resources>

    </global>

    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <federallawyer_customer before="Mage_Customer">Federallawyer_Customer</federallawyer_customer>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Federallawyer_Customer before="Mage_Adminhtml">Federallawyer_Customer_Adminhtml</Federallawyer_Customer>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

    <frontend>
        <layout>
            <updates>
                <customer>
                    <file>federallawyer/customer.xml</file>
                </customer>
            </updates>
        </layout>
    </frontend>

    <adminhtml>
        <layout>
            <updates>
            <customer>
                <file>federallawyer/customer.xml</file>
            </customer>
        </updates>
        </layout>
    </adminhtml>
</config>

But it throw an error in admin end "Fatal error: Call to a member function addFieldToFilter() on a non-object "

Solutions

I cannot understand why you have using

Model,resource model's, prefix identifier as customer. Also you have using

.....
    <global>
         <models>
.....
            <customer> <!-- Model Prefix identifier -->
                <class>Federallawyer_Customer_Model</class>
                <resourceModel>customer_resource</resourceModel>
            </customer>
            <customer_resource> <!-- Resource Model Prefix identifier -->
                <class>Federallawyer_Customer_Model_Resource</class>
                <entities>
                    <cities><table>directory_country_city</table></cities>
                </entities>
            </customer_resource>
....................
        </models>
  .......        
    </global>

Which is already element of Mage_Customer module

That make issue.You need to change to all this.

.....

    <global>
         <models>
.....
            <federallawyercustomer> <!-- change here -->
                <class>Federallawyer_Customer_Model</class>
                <resourceModel>federallawyercustomer_resource</resourceModel> <!-- change here -->
            </federallawyercustomer>
            <federallawyercustomer_resource> <!-- change here -->
                <class>Federallawyer_Customer_Model_Resource</class>
                <entities>
                    <cities><table>directory_country_city</table></cities>
                </entities>
            </federallawyercustomer_resource>
....................
        </models>
  .......        
    </global>

Similar questions

Magento 2 - custom model save triggers error - Fatal error: Call to a member function dispatch() on a non-object
I am creating a simple frontend magento 2 module to take input from user and save output in database. Here is what i have tried. Index.php -- (Index controller index action) namespace Companyname\Faq\Controller; use Magento\Framework\App\RequestInterface; class Index extends \Magento\Framework\App\Action\Action { public function __construct(\Magent...
Magento getting this error: Fatal error: Call to a member function getAttributeText() on a non-object
I am getting the error above in a new template I created in order to show the manufacturer's image. I am using this in the view.phtml file and it works just fine. But since this is custom, I figured there would be problems. Hopefully I can figure this one out. Here is my current code:
Magento export product gives error: "Fatal error Call to a member function getName() on a non-object"
I'm try to export product from magento admin end & getting below error: And also gives the error in the firebug console: How to resolve this error?
Error on invoice Generation - Fatal error: Call to a member function getParentItem() on a non-object
When I try to generate invoices, I get the following error message: This has not always been the case. Can anyone help?
Error: Fatal error: Call to a member function getCode() on a non-object in ;
NO clue what this means. I could get into the admin section and then it would crash out and spit that error again. Upon refresh, I'd get a 503, so I deleted my cache via FTP. At one point I was able to go in and turn on cache for the site along with another thing. Can't get into admin to remember what it was called. Really don't have too many custo...
fatal error: Call to a member function getCollection() on a non-object in magento
I am trying to get a collection of objects of a table of our database. Unfortunately the following code was leading to an error. my code is //config.xml //Model->Easylife.php //Model->Resource->Easylife.php //Model->Resource->Easylife->Collection.php //sql->install-0.0.1.php can anyone tell me where I went wrong? thanks in advance.

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.