1

I am trying a custom extension with table.i have create successfully but it load() function is not working..

Here total extension config.xml path app/code/local/Amit/Productfaq/etc/

<?xml version="1.0"?>
<config>
    <modules>
        <Amit_Productfaq>
            <version>1.0.0</version>
        </Amit_Productfaq>
    </modules>
    <!-- Call Model -->
    <global>
        <models>
            <productfaq>
                <class>Amit_Productfaq_Model</class>
                <resourceModel>productfaq_resource</resourceModel>
            </productfaq>
            <productfaq_resource>
                <class>Amit_Productfaq_Model_Resource</class>
                <entities>
                    <productfaq>productfaq</productfaq>
                </entities>
            </productfaq_resource>
        </models>
        <resources>
            <productfaq_setup>
                <setup>
                    <module>Amit_Productfaq</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </productfaq_setup>
            <productfaq_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </productfaq_read>
            <productfaq_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </productfaq_write>
        </resources>
        <!-- helper -->
        <helpers>
            <productfaq>
                <class>Amit_Productfaq_Helper</class>
            </productfaq>
        </helpers>
    </global>
    <frontend>
        <routers>
            <productfaq>
                <use>standard</use>
                    <args>
                        <module>Amit_Productfaq</module>
                        <frontName>productfaq</frontName>
                    </args>
            </productfaq>
        </routers>
    </frontend>
</config>

Model file are Productfaq.php path app/code/local/Amit/Productfaq/Model

<?php
class Amit_Productfaq_Model_Productfaq extends Mage_Core_Model_Abstract
{
    public function _construct()
    {
        $this->_init('productfaq/productfaq');
    }
    public function abc(){
    return "amit";
    }

}

Productfaq.php app/code/local/Amit/Productfaq/Model/Resource/

<?php
class Amit_Productfaq_Model_Productfaq_Resource_Productfaq extends Mage_Core_Model_Resource_Db_Abstract
{
    protected function _construct()
    {
        $this->_init('productfaq/productfaq', 'productfaq_id');
    }
}

installer install.php \app\code\local\Amit\Productfaq\sql\productfaq_setup

<?php
$installer=$this;
$installer->startSetup();

$installer->run("
-- DROP TABLE IF EXISTS {$this->getTable('productfaq')};
CREATE TABLE {$this->getTable('productfaq')} (
  `productfaq_id` int(11) unsigned NOT NULL auto_increment COMMENT 'Q&A ID',
  `product_id` int(11) NOT NULL  COMMENT 'Product Id' ,
  `customer_name` varchar(255) NOT NULL COMMENT 'Customer Name',
  `customer_email` varchar(255) NOT NULL  COMMENT 'Customer Email',
  `question` text NOT NULL  COMMENT 'Question',
  `answer` text NOT NULL  COMMENT 'Answer',
  `status` smallint(6) NOT NULL default '0' COMMENT 'Status',
  `created_time` datetime NULL,
  `update_time` datetime NULL,
  PRIMARY KEY (`productfaq_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

    ");
$installer->endSetup();
?>

Module file Amit_Productfaq.xml path is app/etc/modules/

<?xml version="1.0"?>
<config>
    <modules>
        <Amit_Productfaq>
            <codePool>local</codePool>
            <active>true</active>
        </Amit_Productfaq>
    </modules>
</config>

Mage::getModel('productfaq/productfaq')->load(1) Show the error "Fatal error: Call to a member function load() on a non-object in C:\wamp\www\magento1702v1\app\code\local\Mage\Core\Model\Abstract.php on line 225".

I have insert the data in table

INSERT INTO `productfaq` (`productfaq_id`, `product_id`, `customer_name`, `customer_email`, `question`, `answer`, `status`, `created_time`, `update_time`) VALUES
(1, 45, 'Amit Bera', 'amit@gmail.com', 'I love you ', 'Mage_Core_Controller_Front_Action', 1, '2014-03-25 00:00:00', '2014-03-31 00:00:00');
1

The error that i can see is this : app/code/local/Amit/Product/etc/(i think that this should be Productfaq, because that is how it is defined in app/etc/modules/Amit_Productfaq.xml - Amit_Productfaq).
Another one can be found here : app/code/local/Amit/Product/Model/Resource/(i think that this also should be Productfaq instead of just Product).
In general make sure that your config nodes match your directory structure.

  • Evgeni,it was my written mistake. check again – Amit Bera Mar 30 '14 at 9:57
1

Yes,after 4hrs works,i resolved the issue. There are issue in config.xml missing syntax <table> in <productfaq_resource> declaretion.

<productfaq_resource>
                <class>Amit_Productfaq_Model_Resource</class>
                <entities>
                    <productfaq>
                    <table>productfaq</table>
                    </productfaq>
                </entities>
            </productfaq_resource>

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.