0
votes

I'm working on Alan Storm's Weblog tutorial. I can retrieve a single record from the model (Model->load(id)) but the call to Model->getCollection() is returning false.

Here is the global section from my config.xml:

<global>
   <models>
      <weblog>
          <class>Magentotutorial_Weblog_Model</class>
          <resourceModel>weblog_resource</resourceModel>
      </weblog>
      <weblog_resource>
        <class>Magentotutorial_Weblog_Model_Resource</class>
        <entities>
            <blogpost>
                <table>blog_posts</table>
            </blogpost>
        </entities>
      </weblog_resource>
  </models>
</global>

My Model in app/code/local/Magentotutorial/Weblog/Model/Blogpost.php:

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

My resource model in app/code/local/Magentotutorial/Weblog/Model/Resource/Blogpost.php - This works, I can call Model->load(id) successfully:

<?php
class Magentotutorial_Weblog_Model_Resource_Blogpost extends Mage_Core_Model_Resource_Db_Abstract {
    protected function _construct()
    {
        $this->_init('weblog/blogpost', 'blogpost_id');
    }
}

My Collection class in app/code/local/Magentotutorial/Weblog/Model/Resource/Blogpost/Collection.php:

<?php
class Magentotutorial_Weblog_Model_Resource_Blogpost_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
    protected function _construct()
    {
            $this->_init('weblog/blogpost');
    }
}

The method in the controller that tries to get the collection. The var_dump call prints "bool(false)":

public function showAllBlogPostsAction() {
    $posts = Mage::getModel('weblog/blogpost')->getCollection();
    var_dump($posts);
    foreach($posts as $blogpost){
      echo '<h3>'.$blogpost->getTitle().'';
      echo nl2br($blogpost->getPost());
}

}

Here is my source tree for the module: enter image description here

Update: I determined that the Collection.php file was not being included. If I include that file manually (from indexController.php) it works. Now I'm trying to figure out why the file isn't getting included.

Thanks very much for any help!

1

1 Answers

0
votes

At some point while coding the tutorial, I had messed up the casing of either the folder names or the classes. I believe I used BlogPost somewhere. I fixed that, but I didn't know that the site I'm working on has a class path cache installed, so when you change the name of a file or directory you have to clear the cache:

sitename/shell>php aoe_classpathcache.php -action clear

The first time I ran that, I got:

Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000] [2002] No such file or directory' in...

To fix that I had to change "localhost" to "127.0.0.1" in my app/etc/local.xml.