I have created a custom module in magento 1.9.And i am trying to load method in my model to controller.But it showing following error. Fatal error: Call to a member function testing() on a non-object. I loaded model in config.xml file as follows.
<models>
<sim_categorynewsletter>
<class>Sim_Categorynewsletter_Model</class>
<resourceModel>newsletter_mysql4</resourceModel>
</sim_categorynewsletter>
<newsletter_mysql4>
<class>Sim_Categorynewsletter_Model_Mysql4</class>
<entities>
<newsletter>
<table>sim_categorynewsletter</table>
</newsletter>
</entities>
</newsletter_mysql4>
</models>
And this is my model class,newsletter.php
<?php
class Sim_Categorynewsletter_Model_Newsletter extends Mage_Core_Model_Abstract
{
protected function _construct(){
$this->_init("categorynewsletter/newsletter");
}
public function testing(){
echo "inside testing method";
}
}
This is my comtroller,IndexController.php.Here i am trying to load the method in models.But its showing error.
<?php
class Sim_Categorynewsletter_IndexController extends Mage_Core_Controller_Front_Action
{
public function createAction(){
echo Mage::getModel('categorynewsletter/newsletter')->testing();
}
}
答案 0 :(得分:0)
我尝试创建相同的方案并发现错误。 将以下代码替换为:
<sim_categorynewsletter>
<class>Sim_Categorynewsletter_Model</class>
<resourceModel>newsletter_mysql4</resourceModel>
</sim_categorynewsletter>
到:
<categorynewsletter>
<class>Sim_Categorynewsletter_Model</class>
<resourceModel>newsletter_mysql4</resourceModel>
</categorynewsletter>