1
votes

I have one controller, say controller ClassA in {magento_root_dir}/app/code/core/Mage/Contacts/controllers and one model object, say ModelB in

{magento_root_dir}/app/code/local/Homeliv/Leads/controllers.

Now I need to access ModelB from ClassA, so that I can save modelB in database.

I have done this:

            $lead = Mage::getModel('local/homeliv/leads/homelivleads');
            $lead->setName('Code Post!');
            $lead->setEmail('This post was created from code!');
            $lead->setMobile(9999);
            $lead->save();

Its throwing error. What I am doing wrong here?

config.xml

<config>
    <modules>
        <Homeliv_Leads>
            <version>0.1.0</version>
        </Homeliv_Leads>
    </modules>
    <global>
    <!-- ... -->
    <models>
        <leads>
            <class>Homeliv_Leads_Model</class>
            <!--
            need to create our own resource, can't just
            use core_resource
            -->
            <resourceModel>leads_resource</resourceModel>
        </leads>
        <leads_resource>
            <class>Homeliv_Leads_Model_Resource</class>
            <entities>
                <homelivleads>
                    <table>homeliv_leads</table>
                </homelivleads>
            </entities>

        </leads_resource>
    </models>
    <!-- ... -->
</global>
</config>

/var/www/html/app/code/local/Homeliv/Leads/Model/HomelivLeads.php :

class Homeliv_Leads_Model_HomelivLeads extends Mage_Core_Model_Abstract
{
    protected function _construct()
    {
        $this->_init('leads/homelivleads');
    }
}

/var/www/html/app/code/local/Homeliv/Leads/Model/Resource/HomelivLeads.php:

class Homeliv_Leads_Model_Resource_HomelivLeads extends Mage_Core_Model_Resource_Db_Abstract{
    protected function _construct()
    {
        $this->_init('leads/homelivleads', 'id');
    }
}

/var/www/html/app/code/local/Homeliv/Leads/Model/Resource/HomelivLeads/Collection.php:

class Homeliv_Leads_Model_Resource_HomelivLeads_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
    protected function _construct()
    {
            $this->_init('leads/homelivleads');
    }
}

/var/www/html/app/etc/modules

<config>
    <modules>
        <Homeliv_Leads>
            <active>true</active>
            <codePool>local</codePool>
        </Homeliv_Leads>
    </modules>
</config>
1
fyi: it shows 500 internal server errorzomato

1 Answers

2
votes

If you have created a separate model here "app/code/local/Homeliv/Leads/Model/", then you can use

$lead = Mage::getModel('leads/homelivleads');