The lex.you need to create a model using a custom module.
Step: You have define model class and resource type but not define resource Class
<models>
<smsnotification>
<class>VivasIndustries_SmsNotification_Model</class> <!-- model prefix class -->
<resourceModel>vivasindustries_smsnotification_resource</resourceModel>
<!-- model resource type -->
</smsnotification>
</models>
So you need to add resource class which is interact the model with database.
<models>
......
<vivasindustries_smsnotification_resource>
<class>VivasIndustries_SmsNotification_Model_Resource</class>
<entities>
<custommodule>
<table>VivasIndustries_SmsNotification</table> <!-- VivasIndustries_SmsNotification is Your db tabale -->
</custommodule>
</entities>
</vivasindustries_smsnotification_resource>
</models>
VivasIndustries_SmsNotification_Model_Resource
VivasIndustries_SmsNotification
you need to define class VivasIndustries_SmsNotification_Model_Smsnotification
code is
<?php
class VivasIndustries_SmsNotification_Model_Smsnotification extends extends Mage_Core_Model_Abstract
{
public function _construct()
{
$this->_init('smsnotification/smsnotification');
}
}
Resource class model class:
<?php
class VivasIndustries_SmsNotification_Model_Resource_Smsnotification extends Mage_Core_Model_Resource_Db_Abstract
{
/**
* Initialize resource model
*
* @return void
*/
public function _construct()
{
$this->_init('smsnotification/smsnotification','id');
}
}
Resource Collection model
<?php
class VivasIndustries_SmsNotification_Model_Resource_Smsnotification_Collection
extends Mage_Core_Model_Resource_Db_Collection_Abstract{
protected function _constuct(){
$this->_init('smsnotification/smsnotification');
}
}
[Please study at how create model][1]
Now you get a collection mode.
Now on preapareCollection
you need change code:
$collection =Mage::getResourceModel('smsnotification/smsnotification_collection);
You grid code is:
<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Smsnotification_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId("smsnotificationGrid");
$this->setDefaultSort("id");
$this->setDefaultDir("DESC");
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel("smsnotification/smsnotification")->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn("id", array(
"header" => Mage::helper("smsnotification")->__("ID"),
"align" =>"right",
"width" => "50px",
"type" => "number",
"index" => "id",
));
$this->addColumn("receiver", array(
"header" => Mage::helper("smsnotification")->__("Receiver"),
"index" => "receiver",
));
$this->addColumn("phone", array(
"header" => Mage::helper("smsnotification")->__("Phome"),
"index" => "phone",
));
$this->addColumn('date', array(
'header' => Mage::helper('smsnotification')->__('Data'),
'index' => 'date',
'type' => 'datetime',
));
$this->addExportType('*/*/exportCsv', Mage::helper('sales')->__('CSV'));
$this->addExportType('*/*/exportExcel', Mage::helper('sales')->__('Excel'));
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return $this->getUrl("*/*/edit", array("id" => $row->getId()));
}
protected function _prepareMassaction()
{
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('ids');
$this->getMassactionBlock()->setUseSelectAll(true);
$this->getMassactionBlock()->addItem('remove_smsnotification', array(
'label'=> Mage::helper('smsnotification')->__('Remove Smsnotification'),
'url' => $this->getUrl('*/adminhtml_smsnotification/massRemove'),
'confirm' => Mage::helper('smsnotification')->__('Are you sure?')
));
return $this;
}
}
Update code at config.xml
<global>
...
<models>
<smsnotification>
<class>VivasIndustries_SmsNotification_Model</class> <!-- model prefix class -->
<resourceModel>vivasindustries_smsnotification_resource</resourceModel>
<!-- model resource type -->
</smsnotification>
<vivasindustries_smsnotification_resource>
<class>VivasIndustries_SmsNotification_Model_Resource</class>
<entities>
<custommodule>
<table>VivasIndustries_SmsNotification</table> <!-- VivasIndustries_SmsNotification is Your db tabale -->
</custommodule>
</entities>
</vivasindustries_smsnotification_resource>
</models>
<resources>
<smsnotification_setup>
<setup>
<module>VivasIndustries_SmsNotification</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</smsnotification_setup>
<smsnotification_write>
<connection>
<use>core_write</use>
</connection>
</smsnotification_write>
<smsnotification_read>
<connection>
<use>core_read</use>
</connection>
</smsnotification_read>
</resources>
.....
</global>
[1]: http://www.amitbera.com/create-an-magento-extension-with-custom-database-table/
Best Answer
phtml files only get called as a template for blocks. Unless you define so in the layout.xml or call it in the php class of the block, it won't be loaded. Since it is all javascript, though, I would make it a .js file and add it with the local.xml into the head of the page with the addJs method.