我正在SocialEngine 4中创建一个新模块。我有一个数据库表advancedrestapi_foods
的模型类,如下所示:
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}
我的表结构:
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 |
+---------------+-------------+------+-----+-------------------+-----------------------------+
答案 0 :(得分:1)