开发者

Can't call method in model table class using Doctrine with Zend Framework

I'm using Doctrine with Zend Framework. For my model, I'm using a base class, the regular class (which extends the base class), and a table class.

In my table class, I've created a method which does a query for records with a specific value for one of the fields in my model. When I try and call this method from my controller, I get an error message saying, "Message: Unknown method Doctrine_Table::getCreditPurchases". Is there something else I need to do to call functions in my table class? Here is my code:

开发者_C百科
class Model_CreditTable extends Doctrine_Table
{
    /**
     * Returns an instance of this class.
     *
     * @return object Model_CreditTable
     */
    public static function getInstance()
    {
        return Doctrine_Core::getTable('Model_Credit');
    }

    public function getCreditPurchases($id)
    {
        $q = $this->createQuery('c')
            ->where('c.buyer_id = ?', $id);

        return $q->fetchArray();
    }
}

// And then in my controller method I have...
$this->view->credits = Doctrine_Core::getTable('Model_Credit')->getCreditPurchases($ns->id);


Man, I'm good at answering my own questions. :)

Found this in the Doctrine docs:

In order for custom Doctrine_Table classes to be loaded you must enable the autoload_table_classes attribute in your bootstrap.php file like done below.

// boostrap.php

// ...
$manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜