Model not working in Magento 1.5.0 from tutorial about Magento's Model and ORM basics

1.6k Views Asked by At

I've been following this tutorial about Magento's Model and ORM basics too. I'm using Magento Version 1.5.0, and when i came across on testing the model if it works specially in printing the object in this code, all i get is a blank white page.

public function testModelAction() {
    $blogpost = Mage::getModel('weblog/blogpost');
    echo get_class($blogpost);
}

I went to see the system log and i get these errors

2011-02-16T04:18:27+00:00 ERR (3): Warning: include(Alanstormdotcom\Weblog\Model\Blogpost.php) [function.include]: failed to open stream: No such file or directory in E:\xampp\htdocs\magento\lib\Varien\Autoload.php on line 94

2011-02-16T04:18:27+00:00 ERR (3): Warning: include() [function.include]: Failed opening 'Alanstormdotcom\Weblog\Model\Blogpost.php' for inclusion (include_path='E:\xampp\htdocs\magento\app\code\local;E:\xampp\htdocs\magento\app\code\community;E:\xampp\htdocs\magento\app\code\core;E:\xampp\htdocs\magento\lib;.;E:\xampp\php\PEAR') in E:\xampp\htdocs\magento\lib\Varien\Autoload.php on line 94

2011-02-16T04:18:27+00:00 ERR (3): Warning: get_class() expects parameter 1 to be object, boolean given in E:\xampp\htdocs\magento\app\code\local\Alanstormdotcom\Weblog\controllers\IndexController.php on line 6

Hope you can help me in resolving this problem..

Thank you..

2

There are 2 best solutions below

5
On

What sort of bum writes a tutorial that doesn't work?!

Take a look at your error message

2011-02-16T04:18:27+00:00 ERR (3): Warning: include(Alanstormdotcom\Weblog\Model\Blogpost.php) [function.include]: failed to open stream: No such file or directory in E:\xampp\htdocs\magento\lib\Varien\Autoload.php on line 94

Magento is telling you it can't find your model file. Have you created the model named Blogpost.php? Is it in the right folder? It should be at

app\code\local\Alanstormdotcom\Weblog\Model\Blogpost.php

If Magento can't find it, that means it's not there. If it is there, than means someone's monkeied with your include path.

1
On

this the Alanstormdotcom\Weblog\Model\Blogspot.php

class Alanstormdotcom_Weblog_Model_Blogpost extends Mage_Core_Model_Abstract
{
    protected function _construct()
    {
        $this->_init('weblog/blogpost');
    }   
}

this is the config.xml

<config>    
    <modules>
        <Alanstormdotcom_Weblog>
            <version>0.1.0</version>
        </Alanstormdotcom_Weblog>
    </modules>
    <frontend>
        <routers>
            <weblog>
                <use>standard</use>
                <args>
                    <module>Alanstormdotcom_Weblog</module>
                    <frontName>weblog</frontName>
                </args>
            </weblog>
        </routers> 
    </frontend>
    <global>
        <models>
            <weblog>
                <class>Alanstormdotcom_Weblog_Model</class>
                <resourceModel>weblog_mysql4</resourceModel>
            </weblog>
        </models>
    </global>   
</config>