一台服务器上的自定义 Magento 模块出现致命错误,另一台服务器上则不然
我正在 Magento 中创建自己的自定义模块,并且在 Litespeed 服务器(PHP v5.2.14)上进行测试期间,我收到一个致命错误:在 ../ 中的非对象上调用成员函数batch()。 ./../BatchController.php 第 25 行 在另一台 linux 服务器和 wamp 服务器(PHP v5.2.11)上测试期间没有出现。
这个把我难住了。我猜这与服务器配置有关,而不是代码本身。但我只是猜测。我希望这里有人能告诉我。
除了 php 版本和环境之外,我能看到的唯一真正的主要区别是错误所在的服务器正在使用 Suhosin 补丁。但这会导致这种情况吗?
有问题的行是 Mage::getModel('mymodule/mymodel')->batch();
,它包含在 IF 语句中。 batch()
是位于我的模型文件中的公共函数。
如果您需要更多代码,请告诉我。
谢谢!
I am creating my own custom module in Magento and during testing on a Litespeed server (PHP v5.2.14) I am getting a Fatal Error: Call to a member function batch() on a non-object in ../../../BatchController.php on line 25
that was not appearing during testing on another linux server and a wamp server (PHP v5.2.11).
This one has stumped me. I am guessing it has something to do with the server configuration rather than the code itself. But i am just guessing. I was hoping someone here could tell me.
The only real major difference I could see, aside from the php versions and environment, is that the server that the error is on is using the Suhosin Patch. But would that be something that could cause this?
The line in question is Mage::getModel('mymodule/mymodel')->batch();
which is enclosed in an IF statement. batch()
is a public function located in my model file.
If you need more code let me know.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您在调用模型时遇到“非对象”错误,则说明 Magento 尝试获取模型类时出现问题,并且返回 null。其原因并不总是显而易见。如果这在正常的 LAMP 堆栈上同样有效,那么问题很可能不在您的代码中。
我的第一个猜测是该文件没有适当的权限。否则,它可能与解析类名有关。您可以通过像这样直接调用插件来暂时测试这一点:
如果这有效,那么该文件是可读的,并且您将想要深入研究该类名的解析。如果它不起作用,则说明您的类的自动加载或声明有问题。
希望有帮助!
谢谢,
乔
If you get a "non-object" error when calling a model, there's a problem with Magento's attempt to get your model class, and it is returning null. The reasons for this are not always apparent. If this worked identically on a normal LAMP stack, then the problem is most likely not in your code.
My first guess would be that the file does not have the proper permissions. Otherwise, it may have to do with resolving the classname. You could test this temporarily by calling the plugin directly like this:
If this works, then the file is readable, and you will want to go spelunking in the resolution of that classname. If it doesn't work, you have a problem with either autoloading or the declaration of your class.
Hope that helps!
Thanks,
Joe
分解它。
您尝试调用
,PHP 告诉您它尝试在非对象上调用批处理方法。这意味着
没有按照预期的方式返回模型对象。
首先要做的就是清除出现问题的服务器上的 Magento 缓存。如果您的模块配置尚未加载到全局配置树中,Magento 将尝试实例化 Mage_Core_Model_Mymodel,并失败。
第二步是确保模块的
app/etc/module
文件就位。第三步是向实例化对象的方法添加一些调试(假设是 1.4 分支)并确定为什么 Magento 无法创建对象
Break it down.
You've tried to call
and PHP told you it tried to call the method batch on a non-object. That means
isn't returning a Model object the way it's supposed to.
First thing to do is clear out your Magento cache on the server you're having problems with. If your Module's config hasn't been loaded into the global config tree Magento will try to instantiate a Mage_Core_Model_Mymodel, and fail.
Second step is to make sure your module's
app/etc/module
file is in place.Third step is to add some debugging (assuming a 1.4 branch) to the method that instantiates your objects and determine why Magento can't create your object