代码之家  ›  专栏  ›  技术社区  ›  Jeremy Hicks

使用Zend框架下的条令不能调用模型表类中的方法

  •  0
  • Jeremy Hicks  · 技术社区  · 16 年前

    我正在使用Zend框架中的理论。对于我的模型,我使用的是基类、常规类(扩展了基类)和表类。

    在我的表类中,我创建了一个方法,用于查询模型中某个字段具有特定值的记录。当我尝试从我的控制器调用这个方法时,我收到一条错误消息,上面写着:“消息:未知方法原理_table::getCreditPurchases”。在我的表类中,还有什么我需要做的来调用函数吗?这是我的代码:

    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);
    
    1 回复  |  直到 16 年前
        1
  •  1
  •   Jeremy Hicks    16 年前

    伙计,我擅长回答自己的问题。:)

    在条令文件中发现:

    为了加载自定义条令表格类,必须在bootstrap.php文件中启用autoload表格类属性,如下所示。

    // boostrap.php
    
    // ...
    $manager->setAttribute(Doctrine_Core::ATTR_AUTOLOAD_TABLE_CLASSES, true);
    
    推荐文章