Create Your First Admin (Backend) Module in Magento

Creating an ‘admin module’ for Magento can eat up your head if you are doing it for the first time. But believe me, after reading this tutorial you will feel it like a child’s play. Here I will tell you the simplest way of creating an admin module in Magento. This tutorial assumes that you are already familiar with creating simple modules in Magento. If you are not, please read this tutorial.

Download Magento Backend Module

Namespace : Company

Module Name : Web


Step 1: Declare your shell module and it’s code pool

Create an xml file /app/etc/modules/Company_Web.xml (You can use any name, even you can use a single file to declare number of modules).

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

Step 2:
Create the basic directory structure under /app/code/core/local/ :-

Company/
|–Web/
| |–Block/
| |–controllers/
| |–etc/
| |–Helper/
| |–sql/
|

Step 3:
Write the front controller in appcodelocalCompanyWebcontrollersIndexController.php
<?php
class Company_Web_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}

Step 4:
Write your backend module controller in appcodelocalCompanyWebcontrollersAdminhtmlWebController.php
<<?php

class Company_Web_Adminhtml_WebController extends Mage_Adminhtml_Controller_action
{

protected function _initAction() {
$this->loadLayout()
->_setActiveMenu('web/items')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));

return $this;
}

public function indexAction() {
$this->_initAction()
->renderLayout();
}

public function editAction() {
$id = $this->getRequest()->getParam('id');
$model = Mage::getModel('web/web')->load($id);

if ($model->getId() || $id == 0) {
$data = Mage::getSingleton('adminhtml/session')->getFormData(true);
if (!empty($data)) {
$model->setData($data);
}

Mage::register('web_data', $model);

$this->loadLayout();
$this->_setActiveMenu('web/items');

$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item Manager'), Mage::helper('adminhtml')->__('Item Manager'));
$this->_addBreadcrumb(Mage::helper('adminhtml')->__('Item News'), Mage::helper('adminhtml')->__('Item News'));

$this->getLayout()->getBlock('head')->setCanLoadExtJs(true);

$this->_addContent($this->getLayout()->createBlock('web/adminhtml_web_edit'))
->_addLeft($this->getLayout()->createBlock('web/adminhtml_web_edit_tabs'));

$this->renderLayout();
} else {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('web')->__('Item does not exist'));
$this->_redirect('*/*/');
}
}

public function newAction() {
$this->_forward('edit');
}

public function saveAction() {
if ($data = $this->getRequest()->getPost()) {

if(isset($_FILES['filename']['name']) && $_FILES['filename']['name'] != '') {
try {
/* Starting upload */
$uploader = new Varien_File_Uploader('filename');

// Any extention would work
$uploader->setAllowedExtensions(array('jpg','jpeg','gif','png'));
$uploader->setAllowRenameFiles(false);

// Set the file upload mode
// false -> get the file directly in the specified folder
// true -> get the file in the product like folders
// (file.jpg will go in something like /media/f/i/file.jpg)
$uploader->setFilesDispersion(false);

// We set media as the upload dir
$path = Mage::getBaseDir('media') . DS ;
$uploader->save($path, $_FILES['filename']['name'] );

} catch (Exception $e) {

}

//this way the name is saved in DB
$data['filename'] = $_FILES['filename']['name'];
}


$model = Mage::getModel('web/web');
$model->setData($data)
->setId($this->getRequest()->getParam('id'));

try {
if ($model->getCreatedTime == NULL || $model->getUpdateTime() == NULL) {
$model->setCreatedTime(now())
->setUpdateTime(now());
} else {
$model->setUpdateTime(now());
}

$model->save();
Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('web')->__('Item was successfully saved'));
Mage::getSingleton('adminhtml/session')->setFormData(false);

if ($this->getRequest()->getParam('back')) {
$this->_redirect('*/*/edit', array('id' => $model->getId()));
return;
}
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
Mage::getSingleton('adminhtml/session')->setFormData($data);
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
return;
}
}
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('web')->__('Unable to find item to save'));
$this->_redirect('*/*/');
}

public function deleteAction() {
if( $this->getRequest()->getParam('id') > 0 ) {
try {
$model = Mage::getModel('web/web');

$model->setId($this->getRequest()->getParam('id'))
->delete();

Mage::getSingleton('adminhtml/session')->addSuccess(Mage::helper('adminhtml')->__('Item was successfully deleted'));
$this->_redirect('*/*/');
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
$this->_redirect('*/*/edit', array('id' => $this->getRequest()->getParam('id')));
}
}
$this->_redirect('*/*/');
}

public function massDeleteAction() {
$webIds = $this->getRequest()->getParam('web');
if(!is_array($webIds)) {
Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Please select item(s)'));
} else {
try {
foreach ($webIds as $webId) {
$web = Mage::getModel('web/web')->load($webId);
$web->delete();
}
Mage::getSingleton('adminhtml/session')->addSuccess(
Mage::helper('adminhtml')->__(
'Total of %d record(s) were successfully deleted', count($webIds)
)
);
} catch (Exception $e) {
Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}

public function massStatusAction()
{
$webIds = $this->getRequest()->getParam('web');
if(!is_array($webIds)) {
Mage::getSingleton('adminhtml/session')->addError($this->__('Please select item(s)'));
} else {
try {
foreach ($webIds as $webId) {
$web = Mage::getSingleton('web/web')
->load($webId)
->setStatus($this->getRequest()->getParam('status'))
->setIsMassupdate(true)
->save();
}
$this->_getSession()->addSuccess(
$this->__('Total of %d record(s) were successfully updated', count($webIds))
);
} catch (Exception $e) {
$this->_getSession()->addError($e->getMessage());
}
}
$this->_redirect('*/*/index');
}

protected function _sendUploadResponse($fileName, $content, $contentType='application/octet-stream')
{
$response = $this->getResponse();
$response->setHeader('HTTP/1.1 200 OK','');
$response->setHeader('Pragma', 'public', true);
$response->setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
$response->setHeader('Content-Disposition', 'attachment; filename='.$fileName);
$response->setHeader('Last-Modified', date('r'));
$response->setHeader('Accept-Ranges', 'bytes');
$response->setHeader('Content-Length', strlen($content));
$response->setHeader('Content-type', $contentType);
$response->setBody($content);
$response->sendResponse();
die;
}
}

Step 5:
Write the frontend block file in appcodelocalCompanyWebBlockWeb.php
<?php
class Company_Web_Block_Web extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}

public function getWeb()
{
if (!$this->hasData('web')) {
$this->setData('web', Mage::registry('web'));
}
return $this->getData('web');

}
}

Step 6: Now write the following file- appcodelocalCompanyWebBlockAdminhtmlWeb.php
<?php
class Company_Web_Block_Adminhtml_Web extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_web';
$this->_blockGroup = 'web';
$this->_headerText = Mage::helper('web')->__('Item Manager');
$this->_addButtonLabel = Mage::helper('web')->__('Add Item');
parent::__construct();
}
}
Step 7: Now write the following file- appcodelocalCompanyWebBlockAdminhtmlWebGrid.php
<?php

class Company_Web_Block_Adminhtml_Web_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('webGrid');
$this->setDefaultSort('web_id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}

protected function _prepareCollection()
{
$collection = Mage::getModel('web/web')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}

protected function _prepareColumns()
{
$this->addColumn('web_id', array(
'header' => Mage::helper('web')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'web_id',
));

$this->addColumn('title', array(
'header' => Mage::helper('web')->__('Title'),
'align' =>'left',
'index' => 'title',
));

/*
$this->addColumn('content', array(
'header' => Mage::helper('web')->__('Item Content'),
'width' => '150px',
'index' => 'content',
));
*/

$this->addColumn('status', array(
'header' => Mage::helper('web')->__('Status'),
'align' => 'left',
'width' => '80px',
'index' => 'status',
'type' => 'options',
'options' => array(
1 => 'Enabled',
2 => 'Disabled',
),
));

$this->addColumn('action',
array(
'header' => Mage::helper('web')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('web')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));

$this->addExportType('*/*/exportCsv', Mage::helper('web')->__('CSV'));
$this->addExportType('*/*/exportXml', Mage::helper('web')->__('XML'));

return parent::_prepareColumns();
}

protected function _prepareMassaction()
{
$this->setMassactionIdField('web_id');
$this->getMassactionBlock()->setFormFieldName('web');

$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('web')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('web')->__('Are you sure?')
));

$statuses = Mage::getSingleton('web/status')->getOptionArray();

array_unshift($statuses, array('label'=>'', 'value'=>''));
$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('web')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('web')->__('Status'),
'values' => $statuses
)
)
));
return $this;
}

public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}

}

Step 8: Now write the following file- appcodelocalCompanyWebBlockAdminhtmlWebEdit.php
<php
class Company_Web_Block_Adminhtml_Web_Edit extends Mage_Adminhtml_Block_Widget_Form_Container
{
public function __construct()
{
parent::__construct();

$this->_objectId = 'id';
$this->_blockGroup = 'web';
$this->_controller = 'adminhtml_web';

$this->_updateButton('save', 'label', Mage::helper('web')->__('Save Item'));
$this->_updateButton('delete', 'label', Mage::helper('web')->__('Delete Item'));

$this->_addButton('saveandcontinue', array(
'label' => Mage::helper('adminhtml')->__('Save And Continue Edit'),
'onclick' => 'saveAndContinueEdit()',
'class' => 'save',
), -100);

$this->_formScripts[] = "
function toggleEditor() {
if (tinyMCE.getInstanceById('web_content') == null) {
tinyMCE.execCommand('mceAddControl', false, 'web_content');
} else {
tinyMCE.execCommand('mceRemoveControl', false, 'web_content');
}
}

function saveAndContinueEdit(){
editForm.submit($('edit_form').action+'back/edit/');
}
";
}

public function getHeaderText()
{
if( Mage::registry('web_data') && Mage::registry('web_data')->getId() ) {
return Mage::helper('web')->__("Edit Item '%s'", $this->htmlEscape(Mage::registry('web_data')->getTitle()));
} else {
return Mage::helper('web')->__('Add Item');
}
}
}
Step 9:
Create the config file as appcodelocalCompanyWebetcconfig.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Web>
<version>0.1.0</version>
</Company_Web>
</modules>
<frontend>
<routers>
<web>
<use>standard</use>
<args>
<module>Company_Web</module>
<frontName>web</frontName>
</args>
</web>
</routers>
<layout>
<updates>
<web>
<file>web.xml</file>
</web>
</updates>
</layout>
</frontend>
<admin>
<routers>
<web>
<use>admin</use>
<args>
<module>Company_Web</module>
<frontName>web</frontName>
</args>
</web>
</routers>
</admin>
<adminhtml>
<menu>
<web module="web">
<title>Web</title>
<sort_order>71</sort_order>
<children>
<items module="web">
<title>Manage Items</title>
<sort_order>0</sort_order>
<action>web/adminhtml_web</action>
</items>
</children>
</web>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<Company_Web>
<title>Web Module</title>
<sort_order>10</sort_order>
</Company_Web>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<web>
<file>web.xml</file>
</web>
</updates>
</layout>
</adminhtml>
<global>
<models>
<web>
<class>Company_Web_Model</class>
<resourceModel>web_mysql4</resourceModel>
</web>
<web_mysql4>
<class>Company_Web_Model_Mysql4</class>
<entities>
<web>
<table>web</table>
</web>
</entities>
</web_mysql4>
</models>
<resources>
<web_setup>
<setup>
<module>Company_Web</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</web_setup>
<web_write>
<connection>
<use>core_write</use>
</connection>
</web_write>
<web_read>
<connection>
<use>core_read</use>
</connection>
</web_read>
</resources>
<blocks>
<web>
<class>Company_Web_Block</class>
</web>
</blocks>
<helpers>
<web>
<class>Company_Web_Helper</class>
</web>
</helpers>
</global>
</config>
Step 10: Now write the helper class appcodelocalCompanyWebHelperData.php
<?php

class Company_Web_Helper_Data extends Mage_Core_Helper_Abstract
{

}

Step 11: Create the model class for your module appcodelocalCompanyWebModelWeb.php
<?php

class Company_Web_Model_Web extends Mage_Core_Model_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('web/web');
}
}

Step 12: Now create appcodelocalCompanyWebModelMysql4Web.php
<?php
class Company_Web_Model_Mysql4_Web extends Mage_Core_Model_Mysql4_Abstract
{
public function _construct()
{
// Note that the web_id refers to the key field in your database table.
$this->_init('web/web', 'web_id');
}
}

Step 13: Now create the collection class appcodelocalCompanyWebModelMysql4WebCollection.php
<?php

class Company_Web_Model_Mysql4_Web_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('web/web');
}
}

Step 14: Now add the mysql setup file as appcodelocalCompanyWebsqlweb_setupmysql4-install-0.1.0.php
<?php

$installer = $this;

$installer->startSetup();

$installer->run("

-- DROP TABLE IF EXISTS {$this->getTable('web')};
CREATE TABLE {$this->getTable('web')} (
`web_id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`filename` varchar(255) NOT NULL default '',
`content` text NOT NULL default '',
`status` smallint(6) NOT NULL default '0',
`created_time` datetime NULL,
`update_time` datetime NULL,
PRIMARY KEY (`web_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

");

$installer->endSetup();

Step 15: Add the layout.xml as appdesignfrontenddefaultdefaultlayoutweb.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
</default>
<web_index_index>
<reference name="content">
<block type="web/web" name="web" template="web/web.phtml" />
</reference>
</web_index_index>
</layout>

Step 16: Now write the following file- appdesignadminhtmldefaultdefaultlayoutweb.xml
<<?xml version="1.0"?>
<layout version="0.1.0">
<web_adminhtml_web_index>
<reference name="content">
<block type="web/adminhtml_web" name="web" />
</reference>
</web_adminhtml_web_index>
</layout>

Step 17: Finally create the template file of your module appdesignfrontenddefaultdefaulttemplatewebweb.phtml
<?php
echo "Welcome to your custom module....";
?>

Written by Arvind Bhardwaj

Arvind is a certified Magento 2 expert with more than 10 years of industry-wide experience.

Website: http://www.webspeaks.in/

113 thoughts on “Create Your First Admin (Backend) Module in Magento

  1. Thank you for your post. it helped me to understand how to create a modules.
    And I read your previous post about simple module – very good post.
    But I can’t see the result of module in this post. I tried to verify again step by step – I see a new tab in Admin side, but the pages ‘Add new’ and ‘Edit’ do not work.

    In the previous example you have shown how we can test this example. I think it would be better if you add to this post the result of this example. It very helped me.

    Thank you for this post.

  2. Hi!
    The file /etc/config.xml, has been updated. Please check if it works now. Only the page ‘Add New’ will work, ‘Edit’ is just for a demo.

  3. Hello!
    Which version of config.xml (step8 or step 9) should be in my file?
    Could you attach archive of this module, please? Or only correct config.file

    Thank you

  4. Hi anonymous!
    Step8 and step9 have been updated, please take a careful reference.
    The file of step9 should be renamed as adminhtml.xml instead of config.xml
    It should work now, please ask if there is some problem. And I will try to attach the archive of this module as soon as possible. Keep updated.
    Good luck!

  5. hello sir
    i follow ur steps to create custom module in admin panel after doing this new menu link comes but page is not working please help me in this.
    Even add new page is not working in this plz help me.
    Waiting for ur reply

  6. Hello,
    I have my menu displayed in admin panel but when I click on “Add New” or “Edit”, I have à 404 not found page error. Is it because I have nothing in My Block/AdminHtml directory?
    Thanks!

  7. Hi,
    I have restart your tutorial and I have not errors!!
    But, I’ve just the admin menu diplayed,the content is blank. My layout doesn’t works Do you have any solution?
    Thanks!

  8. Hello Anonymous,
    I don’t see any error in this tutorial. It is possible that you are missing something. Still I will recheck the tutorial and inform you as soon as possible. Be updated.

  9. i want to make a module realted to social networking like facebook, twitter in the backend i want to manage user info like user email, no of hits and comments how can we do that can u help me i am just beginner of magento.. please help me still waiting for your answer…

  10. I’m also having the problem where the links show in the admin menu and clicking on the add new link doesn’t take you to a 404 page but it just displays an empty content section 🙁

  11. the solution to solve this empty page is change
    “web.xml” file like this:

    web_adminhtml_purchaseorder_index
    reference name=”content”
    block type=”adminhtml/template” name=”purchaseorder” template=”web/purchaseorder.phtml”
    /reference
    /web_adminhtml_purchaseorder_index
    /layout

  12. Managed to get menu working, however when I click “Add New” link I dont get any content in my main block! I have done what isra said. Pls Help!

  13. the solution to solve this empty page is change
    “web.xml” file like this:

    web_adminhtml_purchaseorder_index
    reference name=”content”
    block type=”adminhtml/template” name=”purchaseorder” template=”company_web/purchaseorder.phtml”
    /reference
    /web_adminhtml_purchaseorder_index
    /layout

    This works! missed company_web off template type!

    David

  14. To solve the blank page problem, I add a file web.xml in appdesignADMINHTMLdefaultdefaultlayout with the content:

    < ?xml version=”1.0″? >
    < layout version=”0.1.0″ >
    < default >
    < /default >
    < web_adminhtml_web_index >
    < reference name=”content” >
    < block type=”web/adminhtml_web” name=”web” / >
    < /reference >
    < /web_adminhtml_web_index >
    < /layout >

  15. I am not able to display the page when i am clicking on manage items option from the Web menu so please let me know what kinds of changes i have to made so that it will display the information which are there in manage items page…

    I hope i get reply as soon as possible

  16. I can’t see anything when I am clicking on manage items options at admin side.
    So Please, Let me know about what kind of changes i have to made.

    Hopping for a favorable reply as soon as possible.

  17. i am also getting same problem when i logged in and click on the manage item then blank page appears….

    Please help me

    Thanks in advance

  18. I cleared the cache of magento many times. Still it displays blank page when I clicked on sub menu ‘manage items’. I think, I loose my hours following this module.

  19. Hi,

    Is it working with Magento ver. 1.6.0.0. bcoz when I tried by simply copy pasting your code in app/ folder, it is not showing the tab “Web”, what could be the issue?

  20. There are a number of things in this tutorial I don’t understand. First; step 2. Why create directories in /app/code/core/local/, when all the files in the following steps are stored in /app/code/local/? And if this is an error, why only create a few directories, when you need to create more directories following the steps anyways?

    Why use different indentation among the files, e.g.
    function {
    ..
    }

    function
    {
    ..
    }

    And 1-space, 2-space indentation, etc.

    Also, why the very generic name ‘web’. When I want to name my module Indiana_Jones instead of Company_Web, do I need to replace ALL the words with ‘web’ in the files with ‘jones’, same for the directories? Since Magento also has some function with ‘web’, it isn’t clear to me on first sight, which would be with a different name.

    I’ve followed your tutorial 3 times because I can’t get it to work, nothing shows up. I’m working with Magento 1.6.1

  21. using 1.6.2 i got the menu to work (i had to create a Grid directory under Blocks/Adminhtml and create a Grid.php file containing only the class name), i can click the Menu Items link in the admin menu which displays a page saying ‘Item Manager’ along with a button saying add item, however clicking this button produces a 404 (page not found) error. How is this page generated? the url the link produces changed from having /index/key/{key} to /new/key/{key}

  22. Hello i am using magento 1.5.0.1. It displaying web menu in top but not display anything when i click on Manage Items… what should i do?

  23. Hi Dear,

    The Article is very good to understand the structure of module in magento but the given attachement is not working on newer version. I have tried it on 1.6 version.
    and i followed the steps given in this article to create my own admin module but it wont work i can see menu but on clicking on it is showing me blank page .
    please help me i m novice to magento and didnt got any good help on this .

    your help is appreciable.

  24. Hi Arvin,

    I just checked your module. I downloaded it but I have an issue with error about the database “There has been an error processing your request”. Should I create the database web or as I see your code inside mysql4-install-0.1.0.php should create it itself. When I check the log record it says that Base table or view not found.

    Thanks for your help !

    Kind regards,
    naim

  25. I just downloaded this, and i am getting the database error

    a:5:{i:0;s:105:”SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘e556895_edu_main_website_db.web’ doesn’t exist”;i:1;s:5642:”#0 /home/e556895/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
    #1 /home/e556895/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
    #2 /home/e556895/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
    #3 /home/e556895/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(‘SELECT COUNT(*)…’, Array)
    #4 /home/e556895/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query(‘SELECT COUNT(*)…’, Array)
    #5 /home/e556895/public_html/lib/Zend/Db/Adapter/Abstract.php(825): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
    #6 /home/e556895/public_html/lib/Varien/Data/Collection/Db.php(217): Zend_Db_Adapter_Abstract->fetchOne(Object(Varien_Db_Select), Array)
    #7 /home/e556895/public_html/lib/Varien/Data/Collection.php(225): Varien_Data_Collection_Db->getSize()
    #8 /home/e556895/public_html/lib/Varien/Data/Collection.php(211): Varien_Data_Collection->getLastPageNumber()
    #9 /home/e556895/public_html/lib/Varien/Data/Collection/Db.php(476): Varien_Data_Collection->getCurPage()
    #10 /home/e556895/public_html/lib/Varien/Data/Collection/Db.php(518): Varien_Data_Collection_Db->_renderLimit()
    #11 /home/e556895/public_html/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(526): Varien_Data_Collection_Db->load()
    #12 /home/e556895/public_html/app/code/local/Company/Web/Block/Adminhtml/Web/Grid.php(18): Mage_Adminhtml_Block_Widget_Grid->_prepareCollection()

    and so on?

    any ideas?

    1. @Stefferrs, It seems that the database table for the module was not created. It may be due to permission problems or so. Please create table ‘web’ in your DB and it will be working.

      Thanks.

  26. Hello, i am having trouble with the database, when i got to web –> manage items
    i am getting this database error
    a:5:{i:0;s:105:”SQLSTATE[42S02]: Base table or view not found: 1146 Table ‘e556895_edu_main_website_db.web’ doesn’t exist”;i:1;s:5642:”#0 /home/e556895/public_html/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array)
    #1 /home/e556895/public_html/lib/Zend/Db/Statement.php(300): Varien_Db_Statement_Pdo_Mysql->_execute(Array)
    #2 /home/e556895/public_html/lib/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Statement->execute(Array)
    #3 /home/e556895/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query(‘SELECT COUNT(*)…’, Array)
    #4 /home/e556895/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(389): Zend_Db_Adapter_Pdo_Abstract->query(‘SELECT COUNT(*)…’, Array)
    #5 /home/e556895/public_html/lib/Zend/Db/Adapter/Abstract.php(825): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array)
    #6 /home/e556895/public_html/lib/Varien/Data/Collection/Db.php(217): Zend_Db_Adapter_Abstract->fetchOne(Object(Varien_Db_Select), Array)
    #7 /home/e556895/public_html/lib/Varien/Data/Collection.php(225): Varien_Data_Collection_Db->getSize()
    #8 /home/e556895/public_html/lib/Varien/Data/Collection.php(211): Varien_Data_Collection->getLastPageNumber()
    #9 /home/e556895/public_html/lib/Varien/Data/Collection/Db.php(476): Varien_Data_Collection->getCurPage()
    #10 /home/e556895/public_html/lib/Varien/Data/Collection/Db.php(518): Varien_Data_Collection_Db->_renderLimit()
    #11 /home/e556895/public_html/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php(526): Varien_Data_Collection_Db->load()
    #12 /home/e556895/public_html/app/code/local/Company/Web/Block/Adminhtml/Web/Grid.php(18): Mage_Adminhtml_Block_Widget_Grid->_prepareCollection()

    any ideas why?

  27. Hi there,

    It works like a gem.
    Can you please tell me how to show the data in frontend?

    Thanks!

  28. Hi Arvind..
    it is not working with ver. 1.7.0.0. even the menu is not visible. i have just copied your code, cleared cache.. any idea? please help..
    thanks in advance.

  29. i am using latest version(Magento ver. 1.7.0.1) i have copied all file to the appropriate folders but its not showing any menu in admin ..

    regards

  30. Hi Arvind,

    I download the module and installed and Its working fine. But the problem is when I was creating another Admin User and assigning the custom access to that account then Its not allowing me to give the access to that Role.

    Even I dont see the module name in the list to choose and assign the access.

    When I was using the direct URL to access this module( Acoount having Limited permissions ) Its redirect me to the Dashboard.

    Thanks
    Mahak

    1. Hi Arvind,

      Please let me know If the above issue is fixed?
      ( Allowing the user to access this module. )
      And let me know the steps.
      Thanks in advance.

      Mahak

  31. Hi Arvind,

    I downloaded it just now but it shows a blank page, no error on the logs or on the page,
    my magento version is 1.6.2.0, not sure where to check and change.. 🙁
    Thanks!
    Chris

  32. Great Job , There is an issues with this module . It doesnt show up in giving user role list to give permession to a certian admin role . It would be great if you can sort it out .

  33. Hi Arvind

    Can you tell me the use of
    Step 10: Now write the helper class appcodelocalCompanyWebHelperData.php
    and
    Step 6: Now write the following file- appcodelocalCompanyWebBlockAdminhtmlWeb.php
    because i want to know about its necessity

    Thanks

  34. Hi,

    I hvae downloaded the module and followed it. But i am not able to see even menu tab in admin.
    Plz help me to solve this issue…
    Thanks in advance.

  35. Hi Arvind

    I followed the steps and it executed successfully…
    Thanks for Publishing it…:)
    Now, please can you tell me, how to display the added content in front end.
    Please guide me on it ASAP

  36. Hi Arvind
    I followed these steps and it is working …
    Thanks for publishing this tutorial…:)
    Now, please can you guide me how to displayed added content in frontend..?
    Please guide me on it ASAP.

    1. To access the data you need to create the model object as:
      $model = Mage::getModel(‘web/web’)
      $data = $model->getCollection()->getData();
      print_r($data);

      You must study models in detail to access data in more details.

  37. Please let me know how to resolve the error,

    Thanks in advance 🙂

    ( ! ) SCREAM: Error suppression ignored for
    ( ! ) Fatal error: Class ‘Company_Web_Helper_Data’ not found in D:wampwwwmagentoappMage.php on line 546
    Call Stack
    # Time Memory Function Location
    1 0.0012 379472 {main}( ) ..index.php:0
    2 0.0801 17441160 Mage::run( ) ..index.php:87
    3 0.0819 17505120 Mage_Core_Model_App->run( ) ..Mage.php:683
    4 0.1175 18633712 Mage_Core_Controller_Varien_Front->dispatch( ) ..__default.php:20061
    5 0.1206 18639048 Mage_Core_Controller_Varien_Router_Standard->match( ) ..__default.php:17484
    6 0.1273 18832432 Mage_Core_Controller_Varien_Action->dispatch( ) ..__default.php:17927
    7 0.6949 24368312 Mage_Adminhtml_DashboardController->indexAction( ) ..__default.php:13582
    8 0.9025 31962064 Mage_Core_Controller_Varien_Action->renderLayout( ) ..DashboardController.php:43
    9 0.9028 31963008 Mage_Core_Model_Layout->getOutput( ) ..__default.php:13553
    10 0.9028 31963056 Mage_Core_Block_Abstract->toHtml( ) ..__default.php:27393
    11 0.9030 31963200 Mage_Adminhtml_Block_Template->_toHtml( ) ..__default.php:2518
    12 0.9031 31963200 Mage_Core_Block_Template->_toHtml( ) ..Mage_Adminhtml_Block_Template.php:81
    13 0.9031 31963200 Mage_Core_Block_Template->renderView( ) ..__default.php:3268
    14 0.9036 31963288 Mage_Core_Block_Template->fetchView( ) ..__default.php:3254
    15 0.9042 32031768 include( ‘D:wampwwwmagentoappdesignadminhtmldefaultdefaulttemplatepage.phtml’ ) ..__default.php:3223
    16 0.9521 32595968 Mage_Core_Block_Abstract->getChildHtml( ) ..page.phtml:53
    17 0.9522 32596032 Mage_Core_Block_Abstract->_getChildHtml( ) ..__default.php:2181
    18 0.9522 32596032 Mage_Core_Block_Abstract->toHtml( ) ..__default.php:2237
    19 0.9526 32596312 Mage_Adminhtml_Block_Template->_toHtml( ) ..__default.php:2518
    20 0.9527 32596312 Mage_Core_Block_Template->_toHtml( ) ..Mage_Adminhtml_Block_Template.php:81
    21 0.9527 32596312 Mage_Core_Block_Template->renderView( ) ..__default.php:3268
    22 0.9532 32596408 Mage_Core_Block_Template->fetchView( ) ..__default.php:3254
    23 0.9539 32642736 include( ‘D:wampwwwmagentoappdesignadminhtmldefaultdefaulttemplatepagemenu.phtml’ ) ..__default.php:3223
    24 0.9539 32642736 Mage_Adminhtml_Block_Page_Menu->getMenuArray( ) ..menu.phtml:30
    25 0.9539 32642736 Mage_Adminhtml_Block_Page_Menu->_buildMenuArray( ) ..Mage_Adminhtml_Block_Page_Menu.php:98
    26 1.1353 34312520 Mage_Adminhtml_Block_Page_Menu->_getHelperValue( ) ..Mage_Adminhtml_Block_Page_Menu.php:154
    27 1.1353 34313008 Mage::helper( ) ..Mage_Adminhtml_Block_Page_Menu.php:119

  38. Hi Arvind

    Can you tell me the use of
    Step 10: Now write the helper class appcodelocalCompanyWebHelperData.php
    and
    Step 6: Now write the following file- appcodelocalCompanyWebBlockAdminhtmlWeb.php
    because i want to know about its necessity

    Thanks

  39. Hi Arvind,

    Great tutorial, only forgot one step. The creation of app/code/local/Company/Web/Model/Status.php. For everyone’s convenience, here is the code from the download:
    < ?php

    class Company_Web_Model_Status extends Varien_Object
    {
    const STATUS_ENABLED = 1;
    const STATUS_DISABLED = 2;

    static public function getOptionArray()
    {
    return array(
    self::STATUS_ENABLED => Mage::helper(‘web’)->__(‘Enabled’),
    self::STATUS_DISABLED => Mage::helper(‘web’)->__(‘Disabled’)
    );
    }
    }

  40. This is surely a lot of stuff without any explanation…can you please explain a little what is the code doing at each step…thanks

  41. Error : Fatal error: Call to a member function setData() on a non-object in C:wampwwwmagentoappcodecoreMageAdminhtmlBlockWidgetFormContainer.php on line 129

  42. Thank you for this excellent tutorial.

    I would like to comment on one detail, though.
    Your class Company_Web_Adminhtml_WebController derives from Mage_Adminhtml_Controller_action.
    According to my experiences, this should derive from Mage_Adminhtml_Controller_Action (notice the uppercase A in the end), or else it will stop working once you enable the Magento compiler.

    Kind regards

  43. Thanks a lot Mr. Arvind Bhardwaj. I am new to Magento… Your tutorial is amazing. It works simply great. Thanx again. But Sir… If you will explain this module in detail, it would be very helpful for all of us. I am waiting for your step by step explanation about this tutorial.
    Thank You… 🙂 B-)

  44. Thanks a lot Mr. Arvind Bhardwaj. I am new to Magento. And your tutorial is very helpful for me. I request you, If possible, please explain step by step, so that we can understand the whole working. It would be very helpful for all of us. Thank You again.
    🙂 B-)

  45. hi i am a little confuse because i want to create a new table for other goal, and dont know exactly in the config.xml,
    if i want to add for example web3, and i need to add in the model another file for example web3.php and the same case for the controller?

    :entities:
    :web: –this will be web3?
    : table : web : /table:
    :web :
    : entities:

  46. After doing all these steps, I found menu on admin but onclick of manage items there is error : ‘

    There has been an error processing your request

    Exception printing is disabled by default for security reasons.”

  47. how to solve this when i running this code it showing in magento backend

    Fatal error: Class ‘Company_Web_Helper_Data’ not found in C:xampphtdocsmagento_testappMage.php on line 546

  48. I get this type of Error.what is Solution for this? @Arvind

    ( ! ) Fatal error: Class ‘Company_Web_Helper_Data’ not found in C:wampwwwmagentoappMage.php on line 555
    Call Stack
    # Time Memory Function Location
    1 0.0005 379656 {main}( ) ..index.php:0
    2 0.1452 17703032 Mage::run( ) ..index.php:87
    3 0.1473 17766984 Mage_Core_Model_App->run( ) ..Mage.php:692
    4 0.2151 18997328 Mage_Core_Controller_Varien_Front->dispatch( ) ..__default.php:20465
    5 0.2225 19127808 Mage_Core_Controller_Varien_Router_Standard->match( ) ..__default.php:17865
    6 0.2339 19322304 Mage_Core_Controller_Varien_Action->dispatch( ) ..__default.php:18331
    7 0.2932 21201176 Mage_Adminhtml_DashboardController->indexAction( ) ..__default.php:13969
    8 0.9263 31496392 Mage_Core_Controller_Varien_Action->renderLayout( ) ..DashboardController.php:43
    9 0.9270 31497720 Mage_Core_Model_Layout->getOutput( ) ..__default.php:13941
    10 0.9270 31497768 Mage_Core_Block_Abstract->toHtml( ) ..__default.php:27804
    11 0.9274 31497912 Mage_Adminhtml_Block_Template->_toHtml( ) ..__default.php:2592
    12 0.9275 31497912 Mage_Core_Block_Template->_toHtml( ) ..Mage_Adminhtml_Block_Template.php:81
    13 0.9275 31497912 Mage_Core_Block_Template->renderView( ) ..__default.php:3432
    14 0.9327 31498000 Mage_Core_Block_Template->fetchView( ) ..__default.php:3418
    15 0.9333 31567456 include( ‘C:wampwwwmagentoappdesignadminhtmldefaultdefaulttemplatepage.phtml’ ) ..__default.php:3387
    16 1.2079 32195920 Mage_Core_Block_Abstract->getChildHtml( ) ..page.phtml:53
    17 1.2079 32195984 Mage_Core_Block_Abstract->_getChildHtml( ) ..__default.php:2254
    18 1.2079 32195984 Mage_Core_Block_Abstract->toHtml( ) ..__default.php:2310
    19 1.2090 32196264 Mage_Adminhtml_Block_Template->_toHtml( ) ..__default.php:2592
    20 1.2090 32196264 Mage_Core_Block_Template->_toHtml( ) ..Mage_Adminhtml_Block_Template.php:81
    21 1.2090 32196264 Mage_Core_Block_Template->renderView( ) ..__default.php:3432
    22 1.2099 32196360 Mage_Core_Block_Template->fetchView( ) ..__default.php:3418
    23 1.2147 32243600 include( ‘C:wampwwwmagentoappdesignadminhtmldefaultdefaulttemplatepagemenu.phtml’ ) ..__default.php:3387
    24 1.2148 32243600 Mage_Adminhtml_Block_Page_Menu->getMenuArray( ) ..menu.phtml:30
    25 1.2148 32243600 Mage_Adminhtml_Block_Page_Menu->_buildMenuArray( ) ..Mage_Adminhtml_Block_Page_Menu.php:98
    26 1.6408 33623816 Mage_Adminhtml_Block_Page_Menu->_isEnabledModuleOutput( ) ..Mage_Adminhtml_Block_Page_Menu.php:144
    27 1.6408 33624256 Mage::helper( ) ..Mage_Adminhtml_Block_Page_Menu.php:325

  49. Great. Thanks a lot Arvind…. I am new to Magento. Can you please explain about how to upload multiple image, instead of uploading only one image.

  50. Great. Thanks a Arvind.. I am new to Magento. Can you please explain with example to upload multiple image instead of one image.

  51. hello,sir,I want to add some modules which i have created as per your tutorial & i want to add those modules willl open up in specific externel admin panel from where I can manage items,manage orders & cutomers as well

  52. I get this error when clicked on “Add item”. Fatal error: Call to a member function setData() on a non-object in /var/www/html/p19/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php on line 129
    Can someone help me!!

  53. Hi,
    Actually This is a good tutorial.. As this is not having the Status.php file. Firstly it was showing the error of function(getOptionArray) not defined. but after reading one of the comment I got the code for that file.

    And save it to the desired location. And when I refreshed the page, it shows me “There has been an error processing your request”

    So, is anyone having any idea, why I am getting this error.

    Please help

  54. Hi!! I am new to Magento and followed the prescribed steps. But I can’t run the project. Please tell me the URL for running the project. I am using WAMP.

  55. hello…I have added cancel order link in the my account -> my order section also write the function to take specific action, but when click on the cancel order link it show 404 page not found error.
    Please give me solution.

  56. Hii Arvind this tutorial is good but also explain with comment how exactly flow of this module important functions,classes pls explain

Comments are closed.