我整天都陷入困境,网络搜索的答案中没有一个能解决我的问题,所以我决定在这里发帖。 在后端,它显示标题,菜单和页脚,网格空白空间。
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();
}
}
我/滑块/砌块/ 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();
}
}
我/滑块/砌块/ Adminhtml /滑块/ 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();
}
}
默认/默认/布局/ 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,调用slider.php,调用Grid.php构造函数,但不调用_prepareCollection()和_prepareColumns()。我无法找到原因。我需要你的帮助
尝试而不是使用布局,在控制器中使用以下内容:
$my_block = $this->getLayout()->createBlock('my_slider/adminhtml_slider');
$this->_addContent($my_block);
但没有输出:(
并为以下每一项我得到输出: 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>'));
将添加所需的任何代码或声明,提前致谢。
更新
发现/var/www/magento/app/design/adminhtml/default/default/template/widget/grid.phtml
没有执行,不知道为什么......
答案 0 :(得分:-1)
分析我的模块的源代码,我的做法与你的不同,在网格中创建列。
http://www.magentocommerce.com/magento-connect/dexxtz-custom-grid.html