//If the imageTag could not be saved, dump the error message if (!$imagesTags->save()) { var_dump($imagesTags->getMessages()); $app->response->setStatusCode('500'); $app->response->send(); } $tags[] = $tag; } $image->imagesTags->tags = $tags; //There was an error saving the tags. Dump the error message if (!$image->save()) { var_dump($image->getMessages()); $app->response->setStatusCode('500'); $app->response->send(); } //Return status code 200 if all went well $app->response->setStatusCode('200'); $app->response->setJsonContent([]); $app->response->send(); }); /** * Search for tags */ $app->get('/tags', function () { $request = new Phalcon\Http\Request(); $term = $request->getQuery('term', null, false); $resultSet = Tags::find('name LIKE \'%' . $term . '%\' AND is_used = 1'); echo json_encode($resultSet->toArray()); }); //Handle the request $app->handle();
public function testIssues1265() { $di = new Phalcon\DI\FactoryDefault(); $request = new \Phalcon\Http\Request(); $request->setDI($di); $_REQUEST = $_GET = $_POST = array('string' => 'hello', 'array' => array('string' => 'world')); // get $this->assertEquals($request->get('string', 'string'), 'hello'); $this->assertEquals($request->get('string', 'string', NULL, TRUE, TRUE), 'hello'); $this->assertEquals($request->get('array', 'string'), array('string' => 'world')); $this->assertEquals($request->get('array', 'string', NULL, TRUE, TRUE), NULL); // getQuery $this->assertEquals($request->getQuery('string', 'string'), 'hello'); $this->assertEquals($request->getQuery('string', 'string', NULL, TRUE, TRUE), 'hello'); $this->assertEquals($request->getQuery('array', 'string'), array('string' => 'world')); $this->assertEquals($request->getQuery('array', 'string', NULL, TRUE, TRUE), NULL); // getPost $this->assertEquals($request->getPost('string', 'string'), 'hello'); $this->assertEquals($request->getPost('string', 'string', NULL, TRUE, TRUE), 'hello'); $this->assertEquals($request->getPost('array', 'string'), array('string' => 'world')); $this->assertEquals($request->getPost('array', 'string', NULL, TRUE, TRUE), NULL); }