Phalcon PHP致命错误:消息“未知表达式”的未捕获异常

时间:2014-05-17 06:14:49

标签: php phalcon uncaught-exception

我正在尝试遵循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: });

1 个答案:

答案 0 :(得分:0)

80:     $phql = "INSERT INTO Products (partNumber) VALUES (:partNumber)";
81:     $params = array(
82:         ':partNumber' => $partNumber
83:     );
84:     $status = $app->modelsManager->executeQuery($phql, $params);

我对你所说的Phalcon没有经验,但是从堆栈跟踪看来它似乎是在使用PDO。

第80行:删除了最后一个冒号... VALUES(:partNumber)";

第82行:在数组键的开头添加冒号,这样你就可以得到':partNumber' =>

那将是一个有效的PDO prepare()语句。您的里程可能会有所不同,但这是一个很好的起点。