Magento 排序和筛选在自定义管理模块中不起作用
我试图在magento中实现一个管理模块,在编辑网格实体时,该模块在第一页中有一个网格,在选项卡中有一个网格 主栅格工作正常,但选项卡中的栅格工作不正常 调试代码时我发现的问题是,我正在使用字段过滤在网格中加载集合,即使用用户id的过滤器过滤集合。之所以这样做,是因为我只需要表中单个用户的数据。这就造成了整个问题,网格中的数据是正确的,但网格中的过滤、排序和搜索功能不起作用,并返回404 not found错误页面。我尝试删除在获取集合时添加的字段过滤器,然后它可以正常工作,但表中的所有数据都会出现,这与我的要求相反。 有什么可能的解决办法吗。以下是我尝试的方法:Magento 排序和筛选在自定义管理模块中不起作用,magento,module,grid,Magento,Module,Grid,我试图在magento中实现一个管理模块,在编辑网格实体时,该模块在第一页中有一个网格,在选项卡中有一个网格 主栅格工作正常,但选项卡中的栅格工作不正常 调试代码时我发现的问题是,我正在使用字段过滤在网格中加载集合,即使用用户id的过滤器过滤集合。之所以这样做,是因为我只需要表中单个用户的数据。这就造成了整个问题,网格中的数据是正确的,但网格中的过滤、排序和搜索功能不起作用,并返回404 not found错误页面。我尝试删除在获取集合时添加的字段过滤器,然后它可以正常工作,但表中的所有数据都会
protected function _prepareCollection() {
$collection = Mage::getModel('merchant/subscriptions')->getCollection()->addFieldToFilter('user_id', Mage::registry('merchant_data')->getId());
$this->setCollection($collection); //Set the collection
return parent::_prepareCollection();
}
提前感谢。过滤操作取决于您的以下方法:
public function getGridUrl() {
return $this->getUrl('*/*/grid', array('user_id' => Mage::registry('merchant_data')->getId(),'_current'=>true));
}
以下是您准备收藏的方法:
protected function _prepareCollection()
{
$regData = Mage::registry('merchant_data');
if(isset($regData))
$regData = $regData->getId();
else
$regData = $this->getRequest()->getParam('user_id');
$collection = Mage::getModel('merchant/subscriptions')->getCollection()->addFieldToFilter('user_id',$regData);
...
当我转储$regData时,我得到了以下信息:
Cubet_Merchant_Model_Merchant Object
(
[_eventPrefix:protected] => core_abstract
[_eventObject:protected] => object
[_resourceName:protected] => merchant/merchant
[_resource:protected] =>
[_resourceCollectionName:protected] => merchant/merchant_collection
[_cacheTag:protected] =>
[_dataSaveAllowed:protected] => 1
[_isObjectNew:protected] =>
[_data:protected] => Array
(
[user_id] => 3
[firstname] => Robin
[lastname] => Cubet
[email] => robin@cubettech.com
[username] => robincubet
[password] => 51a7f45eb11fc49b5967a0039193c3ad:HSX8JkSO5lr3uaRHrzd86i7gb0RATeDb
[created] => 2013-12-12 08:34:28
[modified] => 2013-12-16 09:03:56
[logdate] =>
[lognum] => 0
[reload_acl_flag] => 1
[is_active] => 1
[extra] => N;
[rp_token] =>
[rp_token_created_at] =>
)
[_hasDataChanges:protected] =>
[_origData:protected] => Array
(
[user_id] => 3
[firstname] => Robin
[lastname] => Cubet
[email] => robin@cubettech.com
[username] => robincubet
[password] => 51a7f45eb11fc49b5967a0039193c3ad:HSX8JkSO5lr3uaRHrzd86i7gb0RATeDb
[created] => 2013-12-12 08:34:28
[modified] => 2013-12-16 09:03:56
[logdate] =>
[lognum] => 0
[reload_acl_flag] => 1
[is_active] => 1
[extra] => N;
[rp_token] =>
[rp_token_created_at] =>
)
[_idFieldName:protected] => user_id
[_isDeleted:protected] =>
[_oldFieldsMap:protected] => Array
(
)
[_syncFieldsMap:protected] => Array
(
)
)
好的,我的问题解决了,我的代码有一个错误。在网格文件中,下面的函数是错误的
public function getGridUrl() {
return $this->getUrl('*/*/transactiongrid', array('user_id',Mage::registry('merchant_data')->getId(), '_current' => true));
}
正确的方法是
public function getGridUrl() {
return $this->getUrl('*/*/transactiongrid', array('user_id'=> Mage::registry('merchant_data')->getId(), '_current' => true));
}
感谢它的帮助。不过有一个问题。404 not found错误现在不会出现,但是排序、筛选和搜索后的结果返回null。是什么原因导致@Deependra singhy您可以检查
*/*/grid
操作,然后在\u prepareCollection()
中确认每次都正确获取$regData。regData正确到达,它具有userid值。我正在为我在控制器中编写的网格调用操作transactiongrid和subscriptiongrid。公共函数getGridUrl(){return$this->getUrl('*/*/transactiongrid',array('user_id',Mage::registry('merchant_data')->getId(),'''u current'=>true');}这是在控制器中编写的操作:公共函数transactiongridAction(){$This->loadLayout();$This->getResponse()->setBody($This->getLayout()->createBlock('merchant/adminhtml\u merchant\u edit\u tab\u transactiongrid')->toHtml();}你在回答中写的两个函数有什么不同?在“user_id”之后传递的参数中,我首先添加了逗号,实际上它必须是“=>”。这个函数接受两个参数,我传递了三个参数。