简体   繁体   English

致命错误:在非对象上调用成员函数toHtml()

[英]Fatal error: Call to a member function toHtml() on a non-object

I have custom module jewellery. 我有定制的模块首饰。 Tabs used in the admin form in category edit. 类别编辑在管理表单中使用的标签。 Below code is used to add tabs in the admin form. 下面的代码用于在管理表单中添加标签。 it give fatal error 它给出致命错误

Fatal error: Call to a member function toHtml() on a non-object in D:\wamp\www\avita\app\code\local\Mage\Adminhtml\Block\Catalog\Category\Tabs.php on line 158

Below are my files 以下是我的文件

1.) local/Mage/Adminhtml/Block/Catalog/Category/Tabs.php

$this->addTab('upload_prices', array(
'label'     => Mage::helper('catalog')->__('Upload prices'),
'content'   => $this->getLayout()->createBlock('jewellery/adminhtml_catalog_category_product_tab')->toHtml(),
));

2.app/code/local/Subora/Jewellery/etc/config.xml 2.app/code/local/Subora/Jewellery/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Subora_Jewellery>
            <version>0.1.0</version>
        </Subora_Jewellery>
    </modules>
    <global>
        <models>
            <jewellery>
                <class>Subora_Jewellery_Model</class>
            </jewellery>
        </models>
        <helpers>
            <jewellery>
                <class>Subora_Jewellery_Helper</class>
            </jewellery>
        </helpers>
        <blocks>
            <jewellery>
                <class>Subora_Jewellery_Block</class>
            </jewellery>
        </blocks>
        <resources>
            <jewellery_setup>
                <setup>
                    <module>Subora_Jewellery</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </jewellery_setup>
            <jewellery_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </jewellery_write>
            <jewellery_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </jewellery_read>
        </resources>

    </global>
    <adminhtml>
        <layout>
            <updates>
                <jewellery>
                    <file>jewellery.xml</file>
                </jewellery>
            </updates>
        </layout>
        <events>
            <adminhtml_catalog_product_edit_prepare_form>
                <observers>
                    <jewellery_product_edit_prepare_form>
                        <class>jewellery/observer</class>
                        <method>productEditPrepareForm</method>
                    </jewellery_product_edit_prepare_form>
                </observers>
            </adminhtml_catalog_product_edit_prepare_form>
            <catalog_product_save_after>
                <observers>
                    <jewellery_save_product_data>
                        <type>singleton</type>
                        <class>jewellery/observer</class>
                        <method>saveProductTabData</method>
                    </jewellery_save_product_data>
                </observers>
            </catalog_product_save_after>
            <catalog_category_save_after>
                <observers>
                    <jewellery_save_category_data>
                        <type>singleton</type>
                        <class>jewellery/observer</class>
                        <method>saveCategoryTabData</method>
                    </jewellery_save_category_data>
                </observers>
            </catalog_category_save_after>
        </events>

    </adminhtml>

</config> 

3 app\\design\\frontend\\base\\default\\layout\\jewellery.xml 3 app \\ design \\ frontend \\ base \\ default \\ layout \\ jewellery.xml

<?xml version="1.0"?>
<layout version="0.1.0">
  <jewellery_adminhtml_jewellerybackend_index>
    <reference name="content">
      <block type="jewellery/adminhtml_jewellerybackend" name="jewellerybackend"/>
    </reference>
  </jewellery_adminhtml_jewellerybackend_index>

    <jewellery_adminhtml_jewellerybackend_save>
        <reference name="content">
            <block type="jewellery/adminhtml_jewellerybackend_save" name="jewellerybackend_save" template="jewellery/jewellerybackend.phtml" />
        </reference>
    </jewellery_adminhtml_jewellerybackend_save>

    <adminhtml_catalog_product_edit>
        <reference name="product_tabs">
            <action method="addTab">
                <name>subora_jewellery_tab</name>
                <block>jewellery/adminhtml_catalog_product_tab</block>
            </action>
        </reference>
    </adminhtml_catalog_product_edit>

    <adminhtml_catalog_product_new>
        <reference name="product_tabs">
            <action method="addTab">
                <name>subora_jewellery_tab</name>
                <block>jewellery/adminhtml_catalog_product_tab</block>
            </action>
        </reference>
    </adminhtml_catalog_product_new>
</layout>

4.local\\Subora\\Jewellery\\Block\\Adminhtml\\Catalog\\Category\\Product\\Tab.php 4.local \\ Subora \\珠宝\\块\\ Adminhtml \\目录\\目录\\产品\\ Tab.php

<?php
class Subora_Jewellery_Block_Adminhtml_Catalog_Category_Product_Tab extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm() {
        $form = new Varien_Data_Form();

        $this->setForm($form);

        $fieldset = $form->addFieldset('category_import_prices', array('legend'=>Mage::helper('catalog')->__('Import prices')));
        $fieldset->addField('prices', 'file', array(
            'label' => Mage::helper('catalog')->__('Prices file (CSV only)'),
            'name'=> 'prices',
        ));

        return parent::_prepareForm();
    }
}

Now what to do i have tried but cant add tab?? 现在我该怎么办,但无法添加标签?

The problem persists here 问题仍然存在

$this->getLayout()->createBlock('jewellery/adminhtml_catalog_category_product_tab')->toHtml();

toHtml() is calling in a non-object means, createBlock('jewellery/adminhtml_catalog_category_product_tab') is not working correctly. toHtml()以非对象方式调用, createBlock('jewellery/adminhtml_catalog_category_product_tab')无法正常工作。 createBlock() is used to create a new block and add it to the layout. createBlock()用于创建一个新块并将其添加到布局中。 This function has 3 parameters. 此功能有3个参数。

  1. type 2. name 3. attributes 类型2.名称3.属性

you have specified type as jewellery/adminhtml_catalog_category_product_tab . 您已将类型指定为jewellery/adminhtml_catalog_category_product_tab SO magento will look for app/code/local/Subora/Jewellery/Block/Adminhtml/Catalog/Category/Product/Tab.ph‌​p and the file should be properly declared. 因此magento将寻找app/code/local/Subora/Jewellery/Block/Adminhtml/Catalog/Category/Product/Tab.ph‌​p ,并且文件应正确声明。

Next, you need to specify a block name. 接下来,您需要指定一个块名称。 It is necessary. 有必要。 Magento needs all blocks has unique names. Magento需要所有块都有唯一的名称。 Name is absent here. 这里没有名字。

Next parameter is attribute. 下一个参数是属性。 It is optionnal. 这是可选的。 You can set a template by using this parameter. 您可以使用此参数设置模板。 So you can try this code. 因此,您可以尝试此代码。

$this->getLayout()->createBlock(
    'jewellery/adminhtml_catalog_category_product_tab',
    'jewellery.tab',
     array('template' => 'your/template.phtml') //if any
)->toHtml();

EDIT 编辑

First you need to ensure, your module is active or not. 首先,您需要确保模块是否处于活动状态。 You can do this via admin. 您可以通过管理员执行此操作。 System > Configuration > Advanced . System > Configuration > Advanced Check your module is active there. 检查那里的模块是否处于活动状态。

Next thing is, your layout file is in wrong postion. 接下来的事情是,您的布局文件位置错误。 jewellery.xml is an admin layout file. jewellery.xml是一个管理员布局文件。 It should reside in app\\design\\adminhtml\\default\\default\\layout\\jewellery.xml instead of app\\design\\frontend\\base\\default\\layout\\jewellery.xml 它应驻留在app\\design\\adminhtml\\default\\default\\layout\\jewellery.xml而不是app\\design\\frontend\\base\\default\\layout\\jewellery.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:当它是一个对象时,调用非对象上的成员函数 - Fatal Error: Call to member function on non-object when it is an object 致命错误:在非对象错误上调用成员函数prepare() - Fatal error: Call to a member function prepare() on a non-object ERROR 致命错误:在非对象错误上调用成员函数 query() - Fatal error: Call to a member function query() on a non-object Error 错误致命错误:在非对象上调用成员函数insert() - Error Fatal error: Call to a member function insert() on a non-object Magento:致命错误:在非对象上调用成员函数 load() - Magento: Fatal error: Call to a member function load() on a non-object 致命错误:在非对象cakephp上调用成员函数save() - Fatal error: Call to a member function save() on a non-object cakephp 致命错误:在非对象中调用成员函数bindValue() - Fatal error: Call to a member function bindValue() on a non-object in 致命错误:在非对象中调用成员函数login() - Fatal error: Call to a member function login() on a non-object in 致命错误:在magento中的非对象上调用成员函数getEmail() - Fatal error: Call to a member function getEmail() on a non-object in magento 致命错误:在非对象上调用成员函数isVirtual() - Fatal error: Call to a member function isVirtual() on a non-object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM