0
我試圖按照REST應用程序教程provided by Phalcon,但我試圖插入數據時仍遇到問題。我的問題是,我不知道這個錯誤應該是什麼意思。我相信這在Phalcon中是一個錯誤,但我對C的知識是不存在的。讓我知道我是否應該提供更多的上下文。Phalcon PHP致命錯誤:未知的異常與消息「未知的表達式」
下面是在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: });
我切換到使用PDO,但它扔了不同的錯誤。我認爲, Phalcon可以正確配置PHQL,並且這是Phalcon本身的問題。 – acarbonaro