Follow the following steps to create module in admin panel with your custom table.
Create module in your local directory (app/code/local/Pfay/Test), Where test -> .
Inside this structure create all these directories Helper,etc,Block,Model,Controllers
Lets start with etc create config.xml file in side this :
<?xml version="1.0"?>
<config>
<modules>
<Pfay_Test>
<version>1.0.0</version>
</Pfay_Test>
</modules>
<global>
<blocks>
<test>
<class>Pfay_Test_Block</class>
</test>
</blocks>
<models>
<test>
<class>Pfay_Test_Model</class>
<resourceModel>test_mysql4</resourceModel>
</test>
<test_mysql4>
<class>Pfay_Test_Model_Mysql4</class>
<entities>
<test>
<table>pfay_test</table>
</test>
</entities>
</test_mysql4>
</models>
<!-- allow the plugin to read and write -->
<resources>
<!-- connection to write -->
<test_write>
<connection>
<use>core_write</use>
</connection>
</test_write>
<!-- connection to read -->
<test_read>
<connection>
<use>core_read</use>
</connection>
</test_read>
</resources>
<!-- -/- -->
</global>
<frontend>
<routers>
<routeurfrontend>
<use>standard</use>
<args>
<module>Pfay_Test</module>
<frontName>test</frontName>
</args>
</routeurfrontend>
</routers>
<layout>
<updates>
<test>
<file>test.xml</file>
</test>
</updates>
</layout>
</frontend>
<admin>
<routers>
<test>
<use>admin</use>
<args>
<module>Pfay_Test</module>
<frontName>admintest</frontName>
</args>
</test>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<test>
<file>test.xml</file>
</test>
</updates>
</layout>
<menu>
<test translate="title" module="adminhtml">
<title>Import XLS</title>
<sort_order>100</sort_order>
<children>
<set_time>
<title>Add product through XLS</title>
<action>admintest/adminhtml_index</action>
</set_time>
</children>
</test>
</menu>
</adminhtml>
</config>
My table name is Pfay_test add your table name instead of this.
Now in controllers create directory Adminhtml inside this create create your controller IndexController.php
<?php
class Pfay_Test_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
protected function _initAction()
{
$this->loadLayout()->_setActiveMenu('test/set_time')
->_addBreadcrumb('test Manager','test Manager');
return $this;
}
public function indexAction()
{
$this->_initAction();
$this->renderLayout();
}
}
where set_time is you menu name added in config.xml file.
Now move to you block section where you will create you Grid.
Inside Block directory create Adminhtml > Grid.php
class Pfay_Test_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
//where is the controller
$this->_controller = 'adminhtml_test';
$this->_blockGroup = 'test';
//text in the admin header
$this->_headerText = 'XLS file management';
//value of the add button
parent::__construct();
}
}
Next create a directory Test > Grid.php
<?php
class Pfay_Test_Block_Adminhtml_Test_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('contactGrid');
$this->setDefaultSort('id_pfay_test');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('test/test')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('id_pfay_test',
array(
'header' => 'ID',
'align' =>'right',
'width' => '50px',
'index' => 'id_pfay_test',
));
$this->addColumn('nom',
array(
'header' => 'nom',
'align' =>'left',
'index' => 'nom',
));
$this->addColumn('prenom', array(
'header' => 'prenom',
'align' =>'left',
'index' => 'prenom',
));
$this->addColumn('telephone', array(
'header' => 'telephone',
'align' =>'left',
'index' => 'telephone',
));
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
}
Now move to your Model Inside Model create Test.php and Mysql4
In Test.php :
<?php
class Pfay_Test_Model_Test extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('test/test');
}
}
Here (test/test) is Pfay_<modulename>_Model_<modulename> -> (<modulename>/<modulename>)
Now inside Pfay > Test > Model > Mysql4
folder create Test.php and Test
In Test.php :
<?php
class Pfay_Test_Model_Mysql4_Test extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
$this->_init('test/test', 'id_pfay_test');
}
}
Where id_pfay_test is unique key of your table.
Pfay >Test >Model >Mysql4 >Test > create a file Collection.php
<?php
class Pfay_Test_Model_Mysql4_Test_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('test/test');
}
}
Final step inform magento about your module : create file Pfay_Test.xml in
/app/etc/modules
<?xml version="1.0"?>
<config>
<modules>
<Pfay_Test>
<active>true</active>
<codePool>local</codePool>
</Pfay_Test>
</modules>
</config>
Note : Change Module name and package name according to you.
Feel free if you have any query regarding this.