dougan7523 2015-11-17 06:02
浏览 23
已采纳

Magento管理网格不显示只有标题标题和添加按钮存在

Thanks to @PHP Weblineindia for sharing a link for this tutorial http://navaneeth.me/creating-magento-extension-with-custom-database-table/#comment-8147.

I followed almost every details given by this tutorial however I can't display the table grid.

UPDATE: Upon Debugging my model collection has a problem

Another UPDATE: I update all the resource model and collection and extend them to this

Mage_Core_Model_Resource_Db_Abstract -> resource model

Mage_Core_Model_Resource_Db_Collection_Abstract -> Collection model

The good thing is that. I can now add new data to the database.

BUT the main problem still the same, no grid displayed.

I've tried simple data retrieve in magento front end but it give me Fatal error: Call to a member function load() on a non-object.

I'm still new to magento and there are lot of mysteries that I need to discover.

MODEL

app/code/local/Rts/Pmadmin/Model/Pmadmin.php

class Rts_Pmadmin_Model_Pmadmin extends Mage_Core_Model_Abstract {
protected function _construct()
{
    $this->_init('pmadmin/pricematrix');
}
}

app/code/local/Rts/Pmadmin/Model/Mysql4/Resource/Pmadmin.php

class Rts_Pmadmin_Model_Mysql4_Resource_Pmadmin extends Mage_Core_Model_Resource_Db_Abstract {
protected function _construct()
{
    $this->_init('pmadmin/pmadmin', 'pmadmin_id');
}
}

app/code/local/Rts/Pmadmin/Model/Mysql4/Resource/Collection.php

class Rts_Pmadmin_Model_Mysql4_Resource_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
public function _construct()
{
    parent::_construct();
    $this->_init('pmadmin/pmadmin');
}
}

These are the codes.

UPDATED config.xml

<global>
    <helpers>
        <pmadmin>
            <class>Rts_Pmadmin_Helper</class>
        </pmadmin>
    </helpers>
    <blocks>
        <pmadmin>
            <class>Rts_Pmadmin_Block</class>
        </pmadmin>
    </blocks>
    <models>
        <pmadmin>
            <class>Rts_Pmadmin_Model</class>
            <resourceModel>pmadmin_resource</resourceModel>
        </pmadmin>
        <pmadmin_resource>
            <class>Rts_Pmadmin_Model_Resource</class>
            <entities>
                <pmadmin>
                    <table>pmadmin</table>
                </pmadmin>
            </entities>
        </pmadmin_resource>
    </models>
    <resources>
        <pmadmin_setup>
            <setup>
                <module>Rts_Pmadmin</module>
               <class>Rts_Pmadmin_Model_Mysql4_Resource_Mysql4_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </pmadmin_setup>
        <pmadmin_write>
            <connection>
                <use>core_write</use>
            </connection>
        </pmadmin_write>
        <pmadmin_read>
            <connection>
                <use>core_read</use>
            </connection>
        </pmadmin_read>
    </resources>
    </global>

UPDATE: Content block

class Rts_Pmadmin_Block_Adminhtml_Pmadmin_Grid extends Mage_Adminhtml_Block_Widget_Grid {

public function __construct() {
    parent::__construct();
    $this->setId('pmadmingrid');
    $this->setDefaultSort('pmadmin_id');
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(true);
    $this->setUseAjax(true);
}

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

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

    $this->addColumn('title', array(
        'header' => Mage::helper('pmadmin')->__('Title'),
        'align' => 'left',
        'index' => 'title',
        'width' => '50px',
    ));


    $this->addColumn('short_description', array(
        'header' => Mage::helper('pmadmin')->__('Description'),
        'width' => '150px',
        'index' => 'short_description',
    ));

    $this->addColumn('file_path', array(
        'header' => Mage::helper('pmadmin')->__('File Path'),
        'width' => '150px',
        'index' => 'file_path',
    ));


    $this->addColumn('customer_group', array(
        'header' => Mage::helper('pmadmin')->__('Customer Group'),
        'width' => '150px',
        'index' => 'customer_group',
    ));


    $this->addColumn('creation_time', array(
        'header' => Mage::helper('pmadmin')->__('Posted On'),
        'width' => '150px',
        'index' => 'creation_time',
    ));

    return parent::_prepareColumns();
}


public function getRowUrl($row) {
    return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}

public function getGridUrl()
{
  return $this->getUrl('*/*/grid', array('_current'=>true));
}
}

PROBLEM:

  1. No grid is displayed only the header title and the add button

  2. When click add button, the forms are displayed however I can't add new Item

  3. Model Collection return "bool(false)" after var dump

QUESTION:

Can you help me spot the problem?

Thanks

  • 写回答

2条回答 默认 最新

  • duangong937906 2015-11-20 02:37
    关注

    There is a problem with your Model folder structure. I'm not an expert on magento but I think you separate your resource model and collection model into separate folder.

    Based on @Nicolas D answer, I also encounter this problem on magento 1.9.1. It also took me several days to find out the solution.

    Yes, @Nicolas D is right, you have to put your resource folder on Mysql4 folder. However, under Mysql4 folder, you have to create a folder the same name as your module name and put your Collection.php model.

    For example:

    Instead of

    Rts_Pmadmin_Model_Mysql4_Resource
    

    Make it

    Rts_Pmadmin_Model_Mysql4_Pmadmin
    

    Also! Don't forget to update your config.xml and other file related to your changes.

    <models>
        <pmadmin>
            <class>Rts_Pmadmin_Model</class>
            <resourceModel>pmadmin_resource</resourceModel>
        </pmadmin>
        <pmadmin_resource>
            <class>Rts_Pmadmin_Model_Mysql4</class>
            <entities>
                <pmadmin>
                    <table>pmadmin</table>
                </pmadmin>
            </entities>
        </pmadmin_resource>
    </models>
    <resources>
        <pmadmin_setup>
            <setup>
                <module>Rts_Pmadmin</module>
               <class>Rts_Pmadmin_Model_Mysql4_Pmadmin_Mysql4_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </pmadmin_setup>
        <pmadmin_write>
            <connection>
                <use>core_write</use>
            </connection>
        </pmadmin_write>
        <pmadmin_read>
            <connection>
                <use>core_read</use>
            </connection>
        </pmadmin_read>
    </resources>
    

    I don't know if this is a magento bug but this is how we solved our problem.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多