在Windows中成功创建的Magento模型对象在Linux中抛出错误


Magento model object created successfully in Windows throws an error in Linux

我有以下错误发生在我的自定义模块:

致命错误:在非对象上调用成员函数setData()/opt/lampp/根/线上购物/app/代码/地方/Phparrow/Hello/控制器/IndexController.php

我的代码如下-

<标题> config . xml
<global>
    <blocks>
        <hello>
                <class>Phparrow_Hello_Block</class>
        </hello>
    </blocks>
    <helpers>
        <hello>
            <class>Phparrow_Hello_Helper</class>   
        </hello>
    </helpers>
        <models>
            <hello>
                <class>Phparrow_Hello_Model</class>
                <resourceModel>hello_mysql4</resourceModel>
            </hello>
            <hello_mysql4>
                <class>Phparrow_Hello_Model_Mysql4</class>
                <entities>        
                    <hello>
                        <table>hello</table>
                    </hello>
                </entities>
            </hello_mysql4>
        </models>
        <resources>
            <hello_setup>
                <setup>
                    <module>Phparrow_Hello</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </hello_setup>
            <hello_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </hello_write>
            <hello_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </hello_read>
        </resources>
</global> 
<标题>线上购物' app '代码'本地' Phparrow ' Hello '模型' Hello.php h1> 上购物' app ' '本地' Phparrow ' Hello '模型代码' mysql4 ' Hello.php h1> 上购物' app ' '本地' Phparrow ' Hello '模型代码' mysql4 ' Hello ' Collection.php h1> 上购物' app '代码'本地控制器' Phparrow ' Hello ' ' IndexController.php h1> 有一个hello表有三个字段:

hello_id, name, contact

为什么这在Linux中不能工作,而它在Windows中可以成功执行?

我很确定这与你的路径或文件命名有关,确保文件和文件夹的命名与你在这里输入的完全相同。

Windows不太在意,当自动加载器试图找到模型时,可能会提供文件HelLo.php或HelLo.php。

这是在模型中保存数据的正确方法。您需要创建一个数据数组并传入setData()

class Phparrow_Hello_IndexController extends Mage_Core_Controller_Front_Action
{
    public function indexAction()
    { 
     $model1= Mage::getModel('hello/hello');
     $data = array('name'=>'Harsh','contact'=>'8445895621');
     $model1->setData($data);
     $model1->save();
    }
}