2

I'm new in magento so I don't know why this is wrong. Please help. Thanks!

Config.xml

  <?xml version="1.0"?>
  <config>
       <modules>
         <Mymodule_MemberShip>
             <version>1.0.0</version>
         </Mymodule_MemberShip>
     </modules>
     <admin>
         <routers>
             <adminhtml>
                 <args>
                     <modules>
                         <mymodule_membership before="Mage_Adminhtml">Mymodule_MemberShip_Adminhtml</mymodule_membership>
                     </modules>
                 </args>
             </adminhtml>
         </routers>
     </admin>
     <adminhtml>
         <layout>
             <updates>
                 <membership>
                      <file>membership.xml</file>
                 </membership>
             </updates>
         </layout>
     </adminhtml>
     <global>
         <blocks>
             <membership>
                 <class>Mymodule_MemberShip_Block</class>
             </membership>
         </blocks>
         <models>
             <membership>
                 <class>Mymodule_MemberShip_Model</class>
                 <resourceModel>membership_resource</resourceModel>
             </membership>
             <membership_resource>
                 <class>Mymodule_MemberShip_Model_Resource</class>
                 <entities>
                     <package>
                         <table>membership_package</table>
                     </package>
                 </entities>
             </membership_resource>
         </models>
         <resources>
             <membership_setup>
                 <setup>
                     <module>Mymodule_MemberShip</module>
                 </setup>
             </membership_setup>

             <membership_write>
                 <connection>
                     <use>core_write</use>
                 </connection>
             </membership_write>

             <membership_read>
                 <connection>
                     <use>core_read</use>
                 </connection>
             </membership_read>
         </resources>
         <helpers>
             <membership>
                 <class>Mymodule_MemberShip_Helper</class>
             </membership>
         </helpers>
     </global>
 </config>

Mymodule/MemberShip/Block/Adminhtml/Package.php

<?php
class Mymodule_MemberShip_Block_Adminhtml_Package extends 
Mage_Adminhtml_Block_Widget_Grid_Container {
    public function __construct()
    {
        $this->_blockGroup = 'membership';
        $this->_controller = 'adminhtml_package';
        $this->_headerText = $this->__('Package');

        parent::__construct();
    }
}

package.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <adminhtml_package_index>
        <reference name="content">
            <block type="membership/adminhtml_package" name="package"/>
        </reference>
    </adminhtml_package_index>
</layout>

Package.php

<?php
class Mymodule_MemberShip_Block_Adminhtml_Package_Package extends 
Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setDefaultSort('id');
        $this->setId('mymodule_package_package');
        $this->setDefaultDir('asc');
        $this->setSaveParametersInSession(true);
    }
    protected function _getCollectionClass()
    {
        return 'mymodule/package_collection';
    }
    protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }
    protected function _prepareColumns()
    {
        $this->addColumn('id',
            array(
                'header'=> $this->__('ID'),
                'width' => '50px',
                'index' => 'id'
            )
        );
        $this->addColumn('discount_type',
            array(
                'header'=> $this->__('Discount Type'),
                'index' => 'discount_type'
            )
        );
        $this->addColumn('discount_value',
            array(
                'header'=> $this->__('Discount Value'),
                'index' => 'discount_value'
            )
        );
        return parent::_prepareColumns();
     }
    protected function _prepareMassaction()
    {
        $this->setMassactionIdField('id');
        $this->getMassactionBlock()->setFormFieldName('id');
        $this->getMassactionBlock()->addItem('delete', array(
            'label'    => Mage::helper('core')->__('Delete'),
            'url'      => $this->getUrl('*/*/massDelete'),
            'confirm'  => Mage::helper('core')->__('Are you sure?')
        ));

        return $this;
    }
    public function getRowUrl($row)
    {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    }
}
  • can you please add your file path of grid.php file – Rakesh Varma Jul 29 '18 at 15:46
  • @RakeshVarma I updated – Thanh TN Jul 29 '18 at 15:54
  • its your grid container path I am asking for the Grid.php file where you define all grid columns – Rakesh Varma Jul 29 '18 at 15:55
  • @RakeshVarma sorry, my bad. I updated again – Thanh TN Jul 29 '18 at 16:02
  • Check my answer – Rakesh Varma Jul 29 '18 at 16:08
1

Change your grid file class to Mymodule_MemberShip_Block_Adminhtml_Package_Grid and Package.php to Grid.php it will fix your issue. Because in Mage_Adminhtml_Block_Widget_Grid_Container class of core searching for the Grid.php file under Adminhtml/Package folder. Here is the code of core file.

protected function _prepareLayout()
{
    $this->setChild( 'grid',
        $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
        $this->_controller . '.grid')->setSaveParametersInSession(true) );
    return parent::_prepareLayout();
}

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.