2
votes

I'm stuck in this for all the day and no one of the answers from web searching solved my problem, so I decided to post my question here. in backend it's showing header,menu and footer with empty space for grid place.


config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <my_Slider>
            <version>0.0.1</version>
        </my_Slider>
    </modules>
    <global>
        <models>
            <my_slider>
                <class>My_Slider_Model</class>
                <resourceModel>my_slider_resource</resourceModel>
            </my_slider>
            <my_slider_resource>
                <class>My_Slider_Model_Mysql4</class>
                <entities>
                    <slider>
                        <table>my_slider</table>
                    </slider>
                </entities>
            </my_slider_resource>
        </models>
        <resources>
            <my_slider_setup>
                <setup>
                    <module>My_Slider</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </my_slider_setup>
        </resources>
        <helpers>
            <slider>
                <class>My_Slider_Helper</class>
            </slider>
        </helpers>
        <blocks>
            <my_slider>
                <class>My_Slider_Block</class>
            </my_slider>
        </blocks>
    </global>
    <frontend>
        <layout>
            <updates>
                <my_slider>
                    <file>home/slider.xml</file>
                </my_slider>
            </updates>
        </layout>
    </frontend>
    <admin>
        <routers>
            <myslideradmin>
                <use>admin</use>
                <args>
                    <module>my_Slider</module>
                    <frontName>myslideradmin</frontName>
                </args>
            </myslideradmin>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <my_slider>
                    <file>my_slider.xml</file>
                </my_slider>
            </updates>
        </layout>
    </adminhtml>
</config>

SliderController.php

class My_Slider_SliderController extends Mage_Adminhtml_Controller_Action
{
    public function _initAction(){
        $this->_setActiveMenu('myoptions/slider');
        return $this;
    }
    public function indexAction()
    {
        $this->loadLayout();
        $this->_initAction();
        $this->_title(Mage::helper('slider')->__('MY Slider'));
        $this->renderLayout();
    }

}

My/Slider/Block/Adminhtml/Slider.php

class My_Slider_Block_Adminhtml_Slider extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct(){
        $this->_blockGroup  =   'my_slider';
        $this->_controller = 'adminhtml_slider';
        $this->_headerText = Mage::helper('slider')->__('MY - Slider');
        $this->_updateButton('add', 'label', Mage::helper('slider')->__('Add New Slider'));
        parent::_construct();
    }
}

My/Slider/Block/Adminhtml/Slider/Grid.php

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

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


    protected function _prepareColumns()
    {
        $this->addColumn('id', array(
            'header'    => $this->__('ID'),
            'align'     =>'right',
            'width'     => '10px',
            'index'     => 'id',
        ));



        $this->addColumn('title', array(
            'header'    => $this->__('Name'),
            'align'     =>'right',
            'width'     => '10px',
            'index'     => 'title',
        ));

        $this->addColumn('status', array(
            'header'    => $this->__('Status'),
            'align'     =>'right',
            'width'     => '10px',
            'index'     => 'status',
        ));
        return parent::_prepareColumns();
    }
}

default/default/layout/my_slider.xml

<?xml version="1.0"?>
<layout>
    <myslideradmin_slider_index>
        <reference name="content">
            <block type="my_slider/adminhtml_slider" name="my_slider"/>
        </reference>
    </myslideradmin_slider_index>
</layout>

controller is called, slider.php is called, Grid.php constructor is called, but _prepareCollection() and _prepareColumns() are not called. and I couldn't find the reason of this. I need your help


tried instead of using layout, to use in controller the following:

$my_block = $this->getLayout()->createBlock('my_slider/adminhtml_slider');
$this->_addContent($my_block);

but no output :(

and for each of the following I get output: 1-

$my_block = $this->getLayout()->createBlock('my_slider/adminhtml_slider');
$this->_addContent($this->getLayout()->createBlock('core/text')->setText(get_class($my_block)));

2-

$this->_addContent($this->getLayout()->createBlock('core/text')->setText('<h1>Success</h1>'));

any more code or declaration required will be added, Thanks in advance.


updates:


found that /var/www/magento/app/design/adminhtml/default/default/template/widget/grid.phtml is not executing, don't know why..

1

1 Answers

-1
votes

Analyze the source code of my module, I did differently from yours, the creation of columns in the grid.

http://www.magentocommerce.com/magento-connect/dexxtz-custom-grid.html