0
votes

I wrote simple module for magento adminhtml, which contains of controller, model(s), grid and edit form, but when I open module page, I get a error: "Fatal error: Call to a member function order() on a non-object in /var/www/current/lib/Varien/Data/Collection/Db.php on line 500" and nothing more. Show me what I'm doing wrong please!

my etc/config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Company_Mymodule>
            <version>1.0.0</version>
        </Company_Mymodule>
    </modules>
    <global>
        <helpers>
            <company_module>
                <class>Company_Mymodule_Helper</class>
            </company_module>
        </helpers>
        <blocks>
            <company_module>
                <class>Company_Mymodule_Block</class>
            </company_module>
        </blocks>
        <models>
            <company_module>
                <class>Company_Mymodule_Model</class>
                <resourceModel>company_module_mysql4</resourceModel>
            </company_module>
            <company_module_mysql4>
                <class>Company_Mymodule_Model_Mysql4</class>
                <entities>
                    <mymodule>
                        <table>company_module_tm</table>
                    </mymodule>
                </entities>
            </company_module_mysql4>
        </models>
        <resources>
            <company_module_setup>
                <setup>
                    <module>Company_Mymodule</module>
                </setup>
            </company_module_setup>
        </resources>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Company_Mymodule before="Mage_Adminhtml">Company_Mymodule_Adminhtml</Company_Mymodule>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <company_module>
                    <file>company/mymodule.xml</file>
                </company_module>
            </updates>
        </layout>
    </adminhtml>
</config>

my etc/adminhtml.xml

<?xml version="1.0"?>
<config>
    <menu>
        <catalog>
            <children>
                <company_mymodule_tm translate="title" module="company_mymodule">
                    <title>Trade marks</title>
                    <action>adminhtml/tm</action>
                </company_mymodule_tm>
            </children>
        </catalog>
    </menu>
    <acl>
        <resources>
            <admin>
                <children>
                    <catalog>
                        <children>
                            <company_mymodule_tm>
                                <title>Trade marks</title>
                            </company_mymodule_tm>
                        </children>
                    </catalog>
                </children>
            </admin>
        </resources>
    </acl>
</config>

my controllers/Adminhtml/Tm.php

<?php
Class Company_Mymodule_Adminhtml_TmController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        ini_set('display_errors','On');
        error_reporting(E_ALL);
        $this->_initAction();
        $this->_addContent($this->getLayout()->createBlock('company_mymodule/adminhtml_tm_grid'));
        $this->renderLayout();
    }

    public function newAction()
    {
        $this->_forward('edit');
    }

    public function editAction()
    {
        $this->_initAction();

        $id = $this->getRequest()->getParam('id');
        $model = Mage::getModel('company_mymodule/tm');

        if($id)
        {
            $model->load($id);
            if(!$model->getId())
            {
                Mage::getSingleton('adminhtml/session')->addError($this->__('This trade mark no longer exists'));
                $this->_redirect('*/*/');
                return;
            }
        }

        $this->_title($model->getId() ? $model->getTm() : $this->__('New trademark'));

        $data = Mage::getSingleton('adminhtml/session')->getTmData(true);
        if(!empty($data))
        {
            $model->setData($data);
        }

        Mage::register('company_mymodule',$model);

        $this->_initAction()
            ->_addBreadcrumb($id ? $this->__('Edit trade mark') : $this->__('New trade mark'), $id ? $this->__('Edit trade mark') : $this->__('New trade mark'))
            ->addContent($this->getLayout()->createBlock('company_mymodule/adminhtml_tm_edit')->setData('action', $this->getUrl('*/*/save')))
            ->renderLayout();
    }

    public function saveAction()
    {
        if($postData = $this->getRequest()->getPost())
        {
            $model = Mage::getSingleton('company_mymodule/tm');
            $mode->setData($postData);

            try
            {
                $model->save();

                Mage::getSingleton('adminhtml/session')->addSuccess($this->__('The trade mark has been saved'));
                $this->_redirect('*/*/');

                return;
            }
            catch(Mage_Core_Exception $e)
            {
                Mage::getSingleton('adminhtml/session')->addError($e->getMessage());
            }
            catch(Exception $e)
            {
                Mage::getSingleton('adminhtml/session')->addError($this->__('An error occurred while saving this trade mark.'));
            }

            Mage::getSingleton('admin/session')->setTmData($postData);
            $this->_redirectReferer();
        }
    }

    public function messageAction()
    {
        $data = Mage::getModel('company_mymodule/tm')->load($this->getRequest()->getParam('id'));
        echo $data->getContent();
    }

    protected function _initAction()
    {
        $this->loadLayout()
            ->_setActiveMenu('catalog/company_mymodule_tm')
            ->_title($this->__('Trade marks'))
            ->_addBreadcrumb($this->__('Catalog'), $this->__('Catalog'))
            ->_addBreadcrumb($this->__('Trade marks'), $this->__('Trade marks'));

        return $this;
    }

    protected function _isAllowed()
    {
        return Mage::getSingleton('admin/session')->isAllowed('catalog/company_mymodule_tm');
    }
}

my Block/Adminhtml/Tm.php

<?php
Class Company_Mymodule_Block_Adminhtml_Tm extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_blockGroup = 'company_mymodule';
        $this->_controller = 'adminhtml_tm';
        $this->_headerText = $this->__('Trade marks');

        parent::_construct();
    }
}

my Block/Adminhtml/Tm/Grid.php

<?php
Class Company_Mymodule_Block_Adminhtml_Tm_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();

        $this->setDefaultSort('id');
        $this->setId('company_mymodule_tm_grid');
        $this->setDefaultDir('asc');
        $this->setSaveParametersInSession(true);
    }

    protected function _getCollectionClass()
    {
        return 'company_mymodule/tm_collection';
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('company_mymodule/tm')->getCollection(); //
        $this->setCollection($collection);

        return parent::_prepareCollection();
    }

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

        $this->addColumn(
            'tm',
            array(
                'header' => $this->__('Trade mark'),
                'index' => 'tm'
            )
        );

        $this->addColumn(
            'promua_tm',
            array(
                'header' => $this->__('Prom.ua trade mark'),
                'index' => 'promua_tm'
            )
        );

        return parent::_prepareColumns();
    }

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

my Model/Tm.php

<?php
Class Company_Mymodule_Model_Tm extends Mage_Core_Model_Abstract
{
    public function __construct()
    {
        $this->_init('company_mymodule/tm');
    }
}

my Model/Mysql4/Tm.php

<?php
Class Company_Mymodule_Model_Mysql4_Tm extends Mage_Core_Model_Mysql4_Abstract
{
    public function __construct()
    {
        $this->_init('company_mymodule/tm','id');
    }

    public function _construct()
    {
        parent::_construct();
    }
}

my Model/Mysql4/Tm/Collection.php

<?php
Class Company_Mymodule_Model_Mysql4_Tm_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
{
    public function __construct()
    {
        $this->_init('company_mymodule/tm');
    }
}
1

1 Answers

0
votes

I can not see the order function anywhere in your code. It can not give such error. and restof the code is looking good.