在本地文件夹中覆盖时发生Magento错误

这是错误消息:致命错误:调用C: wamp www magento app code core Mage Admin html Block Customer Edit Tabs中的非对象的成员函数initForm()。第58行的php

我复制这个文件:C: wamp www magento app code core Mage Adminhtml Block Customer Edit Accounts.php到:C: wamp www magento app code local MY_PROJECT Adminhtml 块用户编辑标签 Accounts.php

然后编辑这个功能:

<?php

class My_Project_Adminhtml_Block_Customer_Edit_Tab_Account extends Mage_Adminhtml_Block_Customer_Edit_Tab_Account
{

    public function initForm()
    {   
        Mage::log('Debug1: _initForm was called',null,'globe.log');

        $form = new Varien_Data_Form();
        $form->setHtmlIdPrefix('_account');
        $form->setFieldNameSuffix('account');

        $customer = Mage::registry('current_customer');

        /* @var $customerForm Mage_Customer_Model_Form */
        $customerForm = Mage::getModel('customer/form');
        $customerForm->setEntity($customer)
            ->setFormCode('adminhtml_customer')
            ->initDefaultValues();

        $fieldset = $form->addFieldset('base_fieldset',
            array('legend'=>Mage::helper('customer')->__('Account Information'))
        );

        $attributes = $customerForm->getAttributes();

        //Start of edit//
        //Remove the Un-needed labels from the Customer Information Form
        //These are the codes that I added:

        unset($attributes['prefix']);
        unset($attributes['firstname']);
        unset($attributes['middlename']);
        unset($attributes['lastname']);
        unset($attributes['suffix']);
        unset($attributes['taxvat']);
        unset($attributes['dob']);
        unset($attributes['gender']);

        //End of edit//

        foreach ($attributes as $attribute) {
            $attribute->unsIsVisible();
        }
        $this->_setFieldset($attributes, $fieldset);

        /**Usual codes continues here**/

这是Tabs.php的第56-60行代码

$this->addTab('account', array(
        'label'     => Mage::helper('customer')->__('Account Information'),
        'content'   => $this->getLayout()->createBlock('adminhtml/customer_edit_tab_account')->initForm()->toHtml(),
        'active'    => Mage::registry('current_customer')->getId() ? false : true
    ));

我想在这里做的是删除帐户信息表中的姓名,邮编,国家,性别等,只有电子邮件将保留。

如果我在Core文件中完成所有这一切,它一切顺利,但如果我尝试覆盖它并将其保存在本地文件夹中,则会出现此错误。

PS我还在本地添加了config.xml,并在名为My_Project_Adminhtml.xml的C: wamp www magento app etc 模块中添加了一个xml

在此先感谢任何有帮助的人。

这是我的config.xml保存在C: wamp www magento app code local My_Project Adminhtml etc

    <?xml version="1.0" ?>
<config>
    <modules>
        <My_Project_Adminhtml>
            <version>1.0</version>
        </My_Project_Adminhtml>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <customer_edit_tab_account>
                        My_Project_Adminhtml_Block_Customer_Edit_Tab_Account
                    </customer_edit_tab_account>
                </rewrite>
            </adminhtml>
        </blocks>
    </global>
</config>

这是我的模块xml保存在... / app / etc / modules文件夹中

    <?xml version="1.0" ?>
<config>
    <modules>
        <My_Project_Adminhtml>
            <active>true</active>
            <codePool>local</codePool>
        </My_Project_Adminhtml>
    </modules>
</config>

如果你的配置文件布局与此相同,你可能需要删除类名周围的空白,这样它才是节点中唯一的东西。

<adminhtml>
    <rewrite>
        <customer_edit_tab_account>My_Project_Adminhtml_Block_Customer_Edit_Tab_Account</customer_edit_tab_account>
    </rewrite>
</adminhtml>

确保所有XML文件都是正确的XML,两天前我发生了完全相同的事情,因为我拼错了结束标记。 如果这是导致错误,你会在你的system.log中的以下内容

2012-01-23T04:40:31+00:00 ERR (3): Warning: simplexml_load_string(): Entity: line 56: parser error : Opening and ending tag mismatch: 
链接地址: http://www.djcxy.com/p/65177.html

上一篇: Magento Error upon Overriding in local folder

下一篇: Magento 1.5.1: new customer dashboard block