0

I added the code to generate the grid table in admin.But,It is not showing any table in admin panel.Can you please suggest me.

sql

<?php
$installer = $this;
$installer->startSetup();
 $installer->run("CREATE TABLE IF NOT EXISTS mg_childgrowth(
 id int(11) NOT NULL AUTO_INCREMENT,
 gender varchar(60) NOT NULL,  
height varchar(60) NOT NULL,
weight varchar(60) NOT NULL,
  PRIMARY KEY (id)
);");

Mage::getModel('core/url_rewrite')->setId(null);
$installer->endSetup();

config.xml

 <?xml version="1.0"?>
<config>
  <modules>
    <Labwise_Calendar>
      <version>0.1.1</version>
    </Labwise_Calendar>
  </modules>
  <frontend>
  <routers>
    <calendar>
      <use>standard</use>
     <args>
       <module>Labwise_Calendar</module>
       <frontName>calendar</frontName>
     </args>
    </calendar>
  </routers>
  <layout>
      <updates>
          <calendar>
              <file>calendar.xml</file>
          </calendar>
      </updates>
    </layout>
   </frontend>
  <global>



  <helpers>
   <calendar>
       <class>Labwise_Calendar_Helper</class>
   </calendar>
  </helpers>   

     <blocks><calendar><class>Labwise_Calendar_Block</class></calendar></blocks>
         <models>
        <calendar>
            <class>Labwise_Calendar_Model</class>
            <resourceModel>calendar_mysql4</resourceModel>
        </calendar>
        <calendar_mysql4>
            <class>Labwise_Calendar_Model_Mysql4</class>
            <entities>
                <calendar>
                    <table>calendar</table>
                </calendar>
            </entities>
        </calendar_mysql4>
    </models>
    <resources>
        <calendar_setup>
            <setup>
                <module>Labwise_Calendar</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </calendar_setup>
        <calendar_write>
            <connection>
                <use>core_write</use>
            </connection>
        </calendar_write>
        <calendar_read>
            <connection>
                <use>core_read</use>
            </connection>
        </calendar_read>

    </resources>

  </global> 
  <admin>
        <routers>
            <calendar>
                <use>admin</use>
                <args>
                    <module>Labwise_Calendar</module>
                    <frontName>calendar</frontName>
                </args>
            </calendar>
        </routers>
        </admin><adminhtml>
    <menu>
        <calendar module="calendar">
            <title>Calendar</title>
            <sort_order>80</sort_order>
            <children>
            <calendar module="calendar">
                    <title>Manage Calendar</title>
                    <sort_order>10</sort_order>
                    <action>calendar/adminhtml_calendar</action>
                </calendar>
            </children>
        </calendar>
    </menu>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <calendar translate="title" module="calendar">
                        <title>Calendar</title>
                        <sort_order>1000</sort_order>
                        <children>
                            <calendarbackend translate="title">
                                <title>Calendar</title>
                            </calendarbackend><calendar translate="title">
                                <title>Manage Calendar</title>
                            </calendar>
                        </children>
                   </calendar>
                </children>
            </admin>

        </resources>
    </acl>

    <layout>
        <updates>
            <calendar>
                <file>calendar.xml</file>
            </calendar>
        </updates>
    </layout>
</adminhtml>

 </config> 

Grid.php

<?php

  class Labwise_Calendar_Block_Adminhtml_Calendar_Grid extends Mage_Adminhtml_Block_Widget_Grid
 {

    public function __construct()
    {
            parent::__construct();
            $this->setId("calendarGrid");
            $this->setDefaultSort("id");
            $this->setDefaultDir("DESC");
            $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
            $collection = Mage::getModel("calendar/calendar")->getCollection();
            $this->setCollection($collection);
            return parent::_prepareCollection();
    }
    protected function _prepareColumns()
    {
            $this->addColumn("id", array(
            "header" => Mage::helper("calendar")->__("ID"),
            "align" =>"right",
            "width" => "50px",
            "index" => "id",
            ));
            $this->addColumn("age", array(
            "header" => Mage::helper("calendar")->__("Age"),
            "align" =>"left",
            "index" => "age",
            ));

            $this->addColumn("gender", array(
            "header" => Mage::helper("calendar")->__("Gender"),
            "align" =>"left",
            "index" => "gender",
            ));

            $this->addColumn("height", array(
            "header" => Mage::helper("calendar")->__("Height"),
            "align" =>"left",
            "index" => "height",
            ));


            $this->addColumn("weight", array(
            "header" => Mage::helper("calendar")->__("Weight"),
            "align" =>"left",
            "index" => "weight",
            ));


            return parent::_prepareColumns();
    }

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

  }

Controller.php

<?php

      class Labwise_Calendar_Adminhtml_CalendarController extends Mage_Adminhtml_Controller_Action
  {
    protected function _initAction()
    {
                 $this->loadLayout()->_setActiveMenu("calendar/calendar")->_addBreadcrumb(Mage::helper("adminhtml")->__("Calendar Manager"),Mage::helper("adminhtml")->__("calendar Manager"));
            return $this;
    }
    public function indexAction() 
    {
            $this->_initAction();
            $this->renderLayout();
    }
       public function editAction()
    {
            $brandsId = $this->getRequest()->getParam("id");
            $brandsModel = Mage::getModel("calendar/calendar")->load($brandsId);
            if ($brandsModel->getId() || $brandsId == 0) {
                Mage::register("calendar_data", $brandsModel);
                $this->loadLayout();
                $this->_setActiveMenu("calendar/calendar");
                 $this->_addBreadcrumb(Mage::helper("adminhtml")->__("calendar Manager"), Mage::helper("adminhtml")->__("calendar Manager"));
                $this->_addBreadcrumb(Mage::helper("adminhtml")->__("calendar Description"), Mage::helper("adminhtml")->__("calendar Description"));
                $this->getLayout()->getBlock("head")->setCanLoadExtJs(true);
                $this->_addContent($this->getLayout()->createBlock("calendar/adminhtml_calendar_edit"))->_addLeft($this->getLayout()->createBlock("calendar/adminhtml_calendar_edit_tabs"));
                $this->renderLayout();
            } 
            else {
                 Mage::getSingleton("adminhtml/session")->addError(Mage::helper("calendar")->__("Item does not exist."));
                $this->_redirect("*/*/");
            }
    }

    public function newAction()
    {

    $id   = $this->getRequest()->getParam("id");
    $model  = Mage::getModel("calendar/calendar")->load($id);

    $data = Mage::getSingleton("adminhtml/session")->getFormData(true);
    if (!empty($data)) {
        $model->setData($data);
    }

    Mage::register("calendar_data", $model);

    $this->loadLayout();
    $this->_setActiveMenu("calendar/calendar");

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

    $this->_addBreadcrumb(Mage::helper("adminhtml")->__("calendar Manager"), Mage::helper("adminhtml")->__("calendar Manager"));
    $this->_addBreadcrumb(Mage::helper("adminhtml")->__("calendar Description"), Mage::helper("adminhtml")->__("calendar Description"));


    $this->_addContent($this->getLayout()->createBlock("calendar/adminhtml_calendar_edit"))->_addLeft($this->getLayout()->createBlock("calendar/adminhtml_calendar_edit_tabs"));

    $this->renderLayout();

           // $this->_forward("edit");
    }
    public function saveAction()
    {

        $post_data=$this->getRequest()->getPost();

            if ($post_data) {

                try {

                    $path_to_uploaded_image = "";
                    /*if(isset($post_data['calendar_image']['delete']) && $post_data['calendar_image']['delete'] == 1)
                    {
                        $path_to_uploaded_image = "";
                    }*/
                    //$post_data['isregister'] = $post_data['isregister']==1?1:0;

                    $brandsModel = Mage::getModel("calendar/calendar")
                    //->addData($post_data)
                    ->setAge($post_data['age'])
                    ->setGender($post_data['gender'])
                    ->setHeight($post_data['height'])
                    ->setWeight($post_data['weight'])
                    //->setLocation($post_data['location'])
                    //->setMobilenumber($post_data['mobilenumber'])
                    //->setPincode($post_data['pincode'])
                    //->setIsregister($post_data['isregister'])

                    ->setId($this->getRequest()->getParam("id"))
                    ->save();

                    Mage::getSingleton("adminhtml/session")->addSuccess(Mage::helper("adminhtml")->__("calendar was successfully saved"));
                    Mage::getSingleton("adminhtml/session")->setcalendarData(false);

                    if ($this->getRequest()->getParam("back")) {
                        $this->_redirect("*/*/edit", array("id" => $brandsModel->getId()));
                        return;
                    }
                    $this->_redirect("*/*/");
                    return;
                } 
                catch (Exception $e) {
                    Mage::getSingleton("adminhtml/session")->addError($e->getMessage());
                    //Mage::getSingleton("adminhtml/session")->setcalendarData($this->getRequest()->getPost());
                    $this->_redirect("*/*/edit", array("id" => $this->getRequest()->getParam("id")));
                return;
                }

            }
            $this->_redirect("*/*/");
     }



    public function deleteAction()
    {
            if( $this->getRequest()->getParam("id") > 0 ) {
                try {
                    $brandsModel = Mage::getModel("calendar/calendar");
                    $brandsModel->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("*/*/");
     }
  }

calendar.xml

 <?xml version="1.0"?>
 <layout version="0.1.0">
 <calendar_adminhtml_calendarbackend_index>
        <reference name="content">
            <block type="calendar/adminhtml_calendarbackend" name="calendarbackend" template="calendar/calendarbackend.phtml"/>
        </reference>
    </calendar_adminhtml_calendarbackend_index><calendar_adminhtml_calendar_index>
            <reference name="content">
                    <block type="calendar/adminhtml_calendar" name="calendar" />
            </reference>
    </calendar_adminhtml_calendar_index>

  • Assuming you have also created Model and Resource Model files for your module, try turning On developer mode, it will show you errors if it is reading your files correctly. – Prateek Sep 28 '15 at 6:31
  • Ya,I have created those also helper and model files.But it is not showing the grid table. – Mouni Sep 28 '15 at 6:32
  • Then try inserting an error intentionally in your admin layout file, and see your page with developer mode ON. This way you can check if Magento is seeing your layout file or not. – Prateek Sep 28 '15 at 6:35
  • How to check my page in developer Mode ON. – Mouni Sep 28 '15 at 6:38
  • Check here for that - magento.stackexchange.com/questions/15482/… – Prateek Sep 28 '15 at 6:43
0

Mouni, Please refer below links/References, these references will help you to achieve what you are looking for:

http://excellencemagentoblog.com/blog/2011/09/26/admin-part1-series-magento-admin-forms-grids-controllers-tabs/

http://www.pierrefay.com/magento-admin-gridview-85

Otherwise, you need to provide all the code files inside blocks, controller, etc folders. So that we can guide you where you did mistake in code?

Thanks,

  • I have tried by using the above example but it is showing same error.Can you please suggest me to solve the problem. – Mouni Sep 28 '15 at 10:31
  • Moumi, you missed the </layout> tag in calendar.xml layout file. Please add it and check. – Nilesh Tighare Sep 28 '15 at 12:49
  • Ya,I changed it before and added the layout.But,the issue is same. – Mouni Sep 28 '15 at 12:51
  • So, is it working now? – Nilesh Tighare Sep 28 '15 at 12:52
  • No,It is not showing grid table in admin – Mouni Sep 28 '15 at 12:53

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.