【发布时间】:2014-05-17 06:14:49
【问题描述】:
我正在尝试遵循 REST 应用程序教程 provided by Phalcon,但是当我尝试插入数据时,我一直遇到问题。我的问题是我不知道这个错误应该是什么意思。我相信这是 Phalcon 中的一个错误,但我对 C 的了解是不存在的。如果我应该提供更多上下文,请告诉我。
以下是 PHP 错误日志中显示的错误:
PHP Fatal error: Uncaught exception 'Phalcon\\Mvc\\Model\\Exception' with message 'Unknown expression' in /home/acarbonaro/testApplication/index.php:84\n
Stack trace:\n
0 [internal function]: Phalcon\\Mvc\\Model\\Query->_getExpression(274, false)\n
1 [internal function]: Phalcon\\Mvc\\Model\\Query->_prepareInsert()\n
2 [internal function]: Phalcon\\Mvc\\Model\\Query->parse()\n
3 [internal function]: Phalcon\\Mvc\\Model\\Query->execute(Array, NULL)\n
4 /home/acarbonaro/testApplication/index.php(84): Phalcon\\Mvc\\Model\\Manager->executeQuery('INSERT INTO Pro...', Array)\n
5 [internal function]: {closure}()\n
6 /home/acarbonaro/testApplication/index.php(115): Phalcon\\Mvc\\Micro->handle()\n
7 {main}\n
thrown in /home/acarbonaro/testApplication/index.php on line 84
这是 POST 路由的代码,带有行号供参考。
71: $app->post('/api/products', function() use ($app) {
72: if ($app->request->isPost() == true) {
73: if ($app->request->isAjax() == true) {
74: $product = $app->request->getJsonRawBody();
75: $partNumber = $product->partNumber;
76: }
77: $partNumber = $app->request->getPost('partNumber');
78: }
79:
80: $phql = "INSERT INTO Products (partNumber) VALUES (:partNumber:)";
81: $params = array(
82: 'partNumber' => $partNumber
83: );
84: $status = $app->modelsManager->executeQuery($phql, $params);
85:
86: // Prep the response
87: if ($status->success() == true) {
88: $response->setStatusCode(201, "Created");
89:
90: $product->id = $status->getModel()->id;
91:
92: $response->setJsonContent(array('status' => 'OK', 'data' => $product));
93: } else {
94: $response->setStatusCode(409, "Conflict");
95:
96: // Send errors to the client
97: $errors = array();
98: foreach($status->getMessages() as $message) {
99: $errors[] = $message->getMessage();
100: }
101:
102: $response->setJsonContent(array('status' => 'ERROR', 'messages' => $errors));
103: }
104:
105: return $response;
106: });
【问题讨论】:
标签: php phalcon uncaught-exception