无法从 SocialEngine Zend 中的数据库 table 获取行集

Unable to fetch a row set from a db table in SocialEngine Zend

我正在 SocialEngine 4 中创建一个新模块。这里没有太多内容。我有一个数据库 table advancedrestapi_foods 的模型 class 如下:

class Advancedrestapi_Model_DbTable_Foods  extends Engine_Db_Table {

    protected $_name = 'advancedrestapi_foods';
    protected $_primary = 'food_id';
    protected $_rowClass = 'Advancedrestapi_Model_Foods';
    protected $_definition = 'engine4_advancedrestapi_foods';

    public function __toString() {
        return $this->_definition;
    }
}

这是我的索引控制器:

class Advancedrestapi_IndexController extends Core_Controller_Action_Standard {

    public function indexAction() {
        $foodTable = Engine_Api::_()->getDbTable('foods', 'advancedrestapi');
        $db = $foodTable->getAdapter();

        if ($foodTable->error)
            $err = true;

        $rawData = $db->select()
                ->from($foodTable)
                ->where('enabled = ?', true)
                ->query()
                ->fetchAll();
        $this->sendResponse($rawData);

        echo '<script>console.log(' . $err . '");</script>';
        error_log("Food name: " . $foodTable);
    }

    /**
     * HTTP Response Codes
     */
    const HTTP_OK = 200;

    public function sendResponse($data) {
        ob_clean();
        $this->_helper->json($data);
    }

}

当我浏览到插件 http://address/advancedrestapi 的索引页面时,出现此错误:

Zend_Db_Statement_Mysqli_Exception: Mysqli prepare error: Unknown table 'yourdb.engine4_advancedrestapi_foods' in /var/www/html/public_html/application/libraries/Zend/Db/Statement/Mysqli.php:77
Stack trace:
#0 /var/www/html/public_html/application/libraries/Zend/Db/Statement.php(115): Zend_Db_Statement_Mysqli->_prepare('SELECT `engine4...')
#1 /var/www/html/public_html/application/libraries/Zend/Db/Adapter/Mysqli.php(388): Zend_Db_Statement->__construct(Object(Zend_Db_Adapter_Mysqli), 'SELECT `engine4...')
#2 /var/www/html/public_html/application/libraries/Zend/Db/Adapter/Abstract.php(479): Zend_Db_Adapter_Mysqli->prepare('SELECT `engine4...')
#3 /var/www/html/public_html/application/libraries/Zend/Db/Select.php(711): Zend_Db_Adapter_Abstract->query('SELECT `engine4...')
#4 /var/www/html/public_html/application/modules/Advancedrestapi/controllers/IndexController.php(20): Zend_Db_Select->query()
#5 /var/www/html/public_html/application/libraries/Zend/Controller/Action.php(516): Advancedrestapi_IndexController->indexAction()
#6 /var/www/html/public_html/application/libraries/Zend/Controller/Dispatcher/Standard.php(308): Zend_Controller_Action->dispatch('indexAction')
#7 /var/www/html/public_html/application/libraries/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#8 /var/www/html/public_html/application/modules/Core/Bootstrap.php(84): Zend_Controller_Front->dispatch()
#9 /var/www/html/public_html/application/libraries/Engine/Application.php(160): Core_Bootstrap->run()
#10 /var/www/html/public_html/application/index.php(223): Engine_Application->run()
#11 /var/www/html/public_html/index.php(25): include('/var/www/html/p...')
#12 {main}

我的table结构:

 describe engine4_advancedrestapi_foods;

    +---------------+-------------+------+-----+-------------------+-----------------------------+
    | Field         | Type        | Null | Key | Default           | Extra                       |
    +---------------+-------------+------+-----+-------------------+-----------------------------+
    | food_id       | int(11)     | NO   | PRI | NULL              | auto_increment              |
    | title         | varchar(50) | YES  |     | NULL              |                             |
    | creation_date | datetime    | YES  |     | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
    +---------------+-------------+------+-----+-------------------+-----------------------------+

看起来不错,你的代码也适用于我。只需在您的数据库中创建一个 table。 结构如下

CREATE TABLE IF NOT EXISTS `engine4_advancedrestapi_foods` (

food_id int(10) NOT NULL AUTO_INCREMENT, title varchar(50) 不为空, creation_date datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, 主键 (food_id) ) ENGINE=InnoDB 默认字符集=latin1 AUTO_INCREMENT=2 ;