Mage :: getModel返回false [英] Mage::getModel is returning false
问题描述
我正在努力处理在magento中调用和使用模型的问题.
I am trying to get to grips with calling and using models in magento.
我当前的任务是通过从控制器调用简单地显示模型中保存的字符串.
My current task is to simply display a string held in a model by calling it from a controller.
当尝试调用SimpleOutput.php时,我收到一条错误消息,提示已调用非对象.如您所见,我已将其var_dumped并返回false.
When trying to call SimpleOutput.php I get an error message saying that a non object has been called. I have var_dumped it as you will see and it return false.
我查看了我的代码,由于对我在Magento中需要做的工作有有限的了解,所以我了解了所有正确的信息.显然我缺少了一些东西.有人可以看看吗,如果是错别字,告诉我们看哪里,而不仅仅是一个简单的拼写错误,请解释为什么我错过了什么,我应该怎么做以及为什么?
I have looked at my code and with my limited understanding of what I need to do in Magento I have everything correct. Obviously i'm missing something. Could someone please take a look and if it's a typo tell where to look and if it's more than a simple spelling mistake explain what ive missed and what I should have done and why?
我的代码在
Ts/Firstmodule/etc/config.xml
Ts/Firstmodule/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Ts_Firstmodule>
<version>0.1.0</version>
</Ts_Firstmodule>
</modules>
<models>
<firstmodule>
<class>Ts_Firstmodule_Model</class>
</firstmodule>
</models>
<frontend>
<routers>
<firstmodule>
<use>standard</use>
<args>
<module>Ts_Firstmodule</module>
<frontName>firstmodule</frontName>
</args>
</firstmodule>
</routers>
</frontend>
</config>
Ts/Firstmodule/controllers/indexController.php
Ts/Firstmodule/controllers/indexController.php
class Ts_Firstmodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$simple = Mage::getModel('ts_firstmodule/simpleoutput');
var_dump($simple);
}
}
Ts/Firstmodule/model/simpleoutput.php
Ts/Firstmodule/model/simpleoutput.php
class Ts_Firstmodule_Model_SimpleOutput extends Mage_Core_Model_Abstract
{
public function basicText()
{
echo 'this is some text from the simple output model inside the basic text function';
}
}
推荐答案
您必须将<models>
包裹在<global>
中,就像这样:
You must wrap <models>
in <global>
, just like this :
<global>
<models>
<firstmodule>
<class>Ts_Firstmodule_Model</class>
</firstmodule>
</models>
</global>
不要犹豫,看看更简单的核心模块(例如GoogleAnalytics
)的来源,看看它们是如何完成的,并了解其背后的逻辑.
Don't hesitate to take a look at the source of the simpler core modules (eg, GoogleAnalytics
), to see how they're done and understand the logic behind it.
这篇关于Mage :: getModel返回false的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!