There are lot of issue in your module.
Don't create any custom table on Core_Module
It is too bad idea
to create a model
at Core Module(Mage_Customer) and it break magento standard
.
I suggest you need to define model at a new custom module
.
Please the blog how create Model of table.
Model and resource model class was not write properly
If you are using custom Module
and using flat table format
for that Model
then
Model class inherit from Mage_Core_Model_Abstract
.
Resource Model class inherit from Mage_Core_Model_Resource_Db_Abstract
.
Collection Model class inherit from Mage_Core_Model_Resource_Db_Collection_Abstract
.
Insert data;
As you have set multiple fields ,so you need to use addData()
function.
Also you can $id value after model save data
. Basically give the table primary key.
If you define custom module then it config.xml look like:
<?xml version="1.0" ?>
<config>
<modules>
<Amit_Custommodule>
<version>1.0.0</version>
</Amit_Custommodule>
</modules>
<global>
<models>
<!-- Model is define at here -->
<custommodule> <!-- Model Prefix -->
<class>Amit_Custommodule_Model</class>
<resourceModel>custommodule_resource</resourceModel>
</custommodule>
<!-- Resource Model is define at here -->
<custommodule_resource>
<class>Amit_Custommodule_Model_Resource</class>
<entities>
<token> <!-- define an new entities for module -->
<table>customer_token</table> <!-- define table -->
</token>
</entities>
</custommodule_resource>
</models>
<resources>
<custommodule_setup>
<setup>
<module>Amit_Custommodule</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</custommodule_setup>
<custommodule_read>
<connection>
<use>core_read</use>
</connection>
</custommodule_read>
<custommodule_write>
<connection>
<use>core_write</use>
</connection>
</custommodule_write>
</resources>
</global>
</config>
Model class is like :
Model file Token.php path is app/code/community/Amit/Custommodule/Model
<?php
class Amit_Custommodule_Model_Token extends Mage_Core_Model_Abstract
{
public function _construct()
{
$this->_init('custommodule/token');
}
}
ResourceModel:
Resource class Token.php
app/code/community/Amit/Custommodule/Model/Resource/
<?php
class Amit_Custommodule_Model_Resource_Token extends Mage_Core_Model_Resource_Db_Abstract
{
/**
* Initialize resource model
*
* @return void
*/
public function _construct()
{
$this->_init('custommodule/token', 'id');
}
}
Data save Like :
$token = getToken(20);
$data = array('customer_id' => 1, 'token' => $token);
$model = Mage::getModel('custommodule/token')->addData($data);
try {
$model->save(); //save data
$insertId = $model->getId();
echo "Data successfully inserted. Insert ID: " . $insertId;
} catch (Exception $e) {
echo $e->getMessage();
}
Best Answer
or just check your config.xml line should be something like this