我正在开发自定义Magento(1.9.0.1版本)扩展程序。
让我用图片描述你的问题:
当我点击按钮转到下一页时:
然后出现此问题:
正如你所看到的那样,Magento字段指向图片并且中间的Loading
块没有消失的任何原因都在加倍。
让我告诉你我的整个配置文件:
<?xml version="1.0"?>
<config>
<modules>
<VivasIndustries_SmsNotification>
<version>1.0.0</version>
</VivasIndustries_SmsNotification>
</modules>
<global>
<models>
<smsnotification>
<class>VivasIndustries_SmsNotification_Model</class>
<resourceModel>vivasindustries_smsnotification_resource</resourceModel>
</smsnotification>
<vivasindustries_smsnotification_resource>
<class>VivasIndustries_SmsNotification_Model_Resource</class>
<entities>
<smsnotification>
<table>VivasIndustries_SmsNotification</table>
</smsnotification>
<smsnotificationhistory>
<table>VivasIndustries_SmsHistory</table>
</smsnotificationhistory>
</entities>
</vivasindustries_smsnotification_resource>
</models>
<resources>
<smsnotification_setup>
<setup>
<module>VivasIndustries_SmsNotification</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</smsnotification_setup>
<smsnotification_read>
<connection>
<use>core_read</use>
</connection>
</smsnotification_read>
<smsnotification_write>
<connection>
<use>core_write</use>
</connection>
</smsnotification_write>
</resources>
<events>
<sales_order_save_after>
<observers>
<vivasindustries_smsnotification>
<class>smsnotification/observer</class>
<method>orderSaved</method>
</vivasindustries_smsnotification>
</observers>
</sales_order_save_after>
</events>
<helpers>
<smsnotification>
<class>VivasIndustries_SmsNotification_Helper</class>
</smsnotification>
</helpers>
<blocks>
<smsnotification>
<class>VivasIndustries_SmsNotification_Block</class>
</smsnotification>
</blocks>
</global>
<adminhtml>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<system>
<children>
<config>
<children>
<vivas>
<title>Vivas - All</title>
</vivas>
</children>
</config>
</children>
</system>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<smsnotification>
<file>smsnotification.xml</file>
</smsnotification>
</updates>
</layout>
</adminhtml>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
以下是创建网格表的文件:
<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_History extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_sms_history';
$this->_blockGroup = 'smsnotification';
$this->_headerText = Mage::helper('smsnotification')->__('SMS History');
parent::__construct();
$this->_removeButton('add');
}
}
和
<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sms_History_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('smsnotification_grid');
$this->setDefaultSort('id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
protected function _prepareCollection()
{
$collection = Mage::getResourceModel('smsnotification/smsnotificationhistory_collection');
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('id', array(
'header' => Mage::helper('smsnotification')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'id',
));
$this->addColumn('receiver', array(
'header' => Mage::helper('smsnotification')->__('Receiver'),
'align' =>'left',
'index' => 'receiver',
));
$this->addColumn('phone', array(
'header' => Mage::helper('smsnotification')->__('Phone'),
'align' =>'left',
'index' => 'phone',
));
$this->addColumn('email', array(
'header' => Mage::helper('smsnotification')->__('Email'),
'align' =>'left',
'index' => 'email',
));
$this->addColumn('smstext', array(
'header' => Mage::helper('smsnotification')->__('SMS Text'),
'align' =>'left',
'index' => 'smstext',
));
$this->addColumn('date', array(
'header' => Mage::helper('smsnotification')->__('Date'),
'align' =>'left',
'index' => 'date',
));
return parent::_prepareColumns();
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id'=>$row->getId()));
}
}
我不知道我的错误在哪里以及为什么它会使这些领域翻倍。 你知道如何解决这个问题吗?
谢谢!
答案 0 :(得分:0)
当您使用方法setUseAjax
时,Magento将尝试通过ajax重新加载页面中的网格。
因此,为了实现这一点,您必须向Magento指定他需要获取哪个URL以获取网格以及仅通过ajax刷新网格,否则它将错误地假设它必须刷新具有当前页面url的网格,因此在div中第二次添加admin的标题应该只保留网格。就像你的截图一样。
还有办法:
在VivasIndustries_SmsNotification_Block_Adminhtml_Sms_History_Grid
中添加此功能:
public function getGridUrl()
{
return $this->getUrl('*/*/smsGrid', array('_current'=>true));
}
因此,您还必须将此操作添加到VivasIndustries_SmsNotification_Adminhtml
的控制器中,并使用您的网格渲染块,并且只显示此块。
像那样:
public function smsGridAction()
{
$this->getResponse()
->setBody($this->getLayout()
->createBlock('smsnotification/adminhtml_sms_history_grid')
->toHtml()
);
}
你应该好好去。