Magento – Mage::getModel() fail to load the model

databasemagento-1.9model

I am trying to learn Magento hard and although I have good understandig of OOP and programming ,still struggling.I am following tutorials ,do the same as there and got errors ,which is very dissapointing.I made module ,this is my config.xml :

<?xml version="1.0"?>
<config>
    <modules>
        <Foggyline_HappyHour>
            <version>1.0.0.0</version>
        </Foggyline_HappyHour>
    </modules>
    <global>
        <models>
 <foggyline_happyhour>
 <class>Foggyline_HappyHour_Model</class>
 <resourceModel>foggyline_happyhour_resource</resourceModel>
 </foggyline_happyhour>
 <foggyline_happyhour_resource>
 <class>Foggyline_HappyHour_Model_Resource</class>
 <entities>
 <user>
 <table>foggyline_happyhour_user</table>
 </user>
 </entities>
 </foggyline_happyhour_resource>
 </models>
 <resources>
 <foggyline_happyhour_setup>
 <setup>
 <model>Foggyline_HappyHour</model>
 </setup>
 </foggyline_happyhour_setup>
 </resources>
    <blocks>
 <foggyline_happyhour>
 <class>Foggyline_HappyHour_Block</class>
 </foggyline_happyhour>
 </blocks>
 </global>
    <frontend>
        <routers>
            <foggyline_happyhour>
                <use>standard</use>
                <args>
                    <module>Foggyline_HappyHour</module>
                    <frontName>happyhour</frontName>
                </args>
            </foggyline_happyhour>
        </routers>
    </frontend>
</config>

In the Model folder I have first User.php :

<?php

class Foggyline_HappyHour_Model_User extends Mage_Core_Model_Abstract
{
   protected $_eventPrefix      = 'foggyline_happyhour_user';
   protected $_eventObject      = 'user';

   protected function _construct()
   {
       $this->_init('foggyline_happyhour/user');
   }
}

in Model/Resuource/User.php :

<?php

class Foggyline_HappyHour_Model_Resource_User extends Mage_Core_Model_Resource_Db_Abstract
{
   protected function _construct()
   {
       $this->_init('foggyline_happyhour/user', 'user_id');
   }
}

and Model/Resuorce/User/Collection.php :

<?php

class Foggyline_HappyHour_Model_Resource_User_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
   public function _construct()
   {
       $this->_init('foggyline_happyhour/user');
   }
}

Also there is some init script for the database ,I don't know whether this is problem with database or something like this?

in my controller I have this function : 
public function testAction(){
        $obj=Mage::getModel('foggyline_happyhour/user');
        var_dump($obj);
     }

page is just crashing with this code ,if I put capital letters 'Foggyline_Happyhour ,page is not crashing and show bool(false) ,which should mean nothing is instantiated,how do I fix this mess is the big question ? I am using Linux btw

Best Answer

in your config.xml, under resources/foggyline_happyhour_setup/setup, you have defined a model tag, but I think it has to be module: https://github.com/bragento/magento-core/blob/1.9/app/code/core/Mage/Cms/etc/config.xml#L167

Also look in you database, if the foggyline_happyhour_user table is created (most likely after you fixed the config.xml and cleared the cache)

Related Topic