I got a problem loading a second model handling a database with a module.
I got 1 controller ValidateController and 2 Models Main that extends Mage_Core_Controller_Front_Action so I can’t communicate with the database, and Log that communicates with the database.
When I call $log = Mage::getModel('modulex/log'); it is fine it gives me the correct path for with get_class($log) but when I call $log->load($params['id']); it fails giving me this error:
Warning: include(Companyx/Modulex/Model/Resource/Main.php) [function.include]: failed to open stream: No such file or directory
I don’t see why it gives me this error, it should call Resource/Log.php that exists.
I show you my config.xml
<frontend>
<routers>
<modulex>
<use>standard</use>
<args>
<module>Companyx_Modulex</module>
<frontName>modulex</frontName>
</args>
</modulex>
</routers>
</frontend>
<global>
<models>
<modulex>
<class>Companyx_Modulex_Model</class>
<resourceModel>modulex_resource</resourceModel>
</modulex>
<modulex_resource>
<class>Companyx_Modulex_Model_Resource</class>
<entities>
<log>
<table>companyx_modulex_logs</table>
</log>
</entities>
</modulex_resource>
</models>
</global>
Thank you for your help !
==== EDIT SOLUTION ====
Create /resource/Main.php with this code
class Companyx_Modulex_Model_Resource_Main extends Mage_Core_Model_Resource_Db_Abstract
{
protected function _construct()
{
$this->_init('modulex/log', 'id');
}
}
My mistake was doing $this->_init('modulex/main', 'id');.
The error message that you are receiving i reasonably clear, the resource model isn’t found. Magento splits models into what is essentially a 2 layer system. One layer for dealing with business logic and the other layer for dealing with persistence / database interaction. When you call load on your model, this is proxied off to the resource model specified for you class. In your configuration this resource is being set-up as
Companyx_Modulex_Model_Resource_Main.php, but you seemingly don’t have a file in the location the class is supposed to be defined –app/code/{codepool}/Companyx/Modulex/Model/Resource/Main.php.