Пример #1
0
 public function testMicroClass()
 {
     $handler = new RestHandler($this);
     $app = new Phalcon\Mvc\Micro();
     $app->get('/api/site', array($handler, 'find'));
     $app->post('/api/site/save', array($handler, 'save'));
     $app->delete('/api/site/delete/1', array($handler, 'delete'));
     //Getting the url from _url using GET
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_GET['_url'] = '/api/site';
     $app->handle();
     $this->assertEquals($handler->getNumberAccess(), 1);
     $this->assertEquals($handler->getTrace(), array('find'));
     //Getting the url from _url using POST
     $_SERVER['REQUEST_METHOD'] = 'POST';
     $_GET['_url'] = '/api/site/save';
     $app->handle();
     $this->assertEquals($handler->getNumberAccess(), 2);
     $this->assertEquals($handler->getTrace(), array('find', 'save'));
     //Passing directly a URI
     $_SERVER['REQUEST_METHOD'] = 'DELETE';
     $_GET['_url'] = null;
     $app->handle('/api/site/delete/1');
     $this->assertEquals($handler->getNumberAccess(), 3);
     $this->assertEquals($handler->getTrace(), array('find', 'save', 'delete'));
 }
Пример #2
0
        $response->setJsonContent(['status' => 'OK']);
    }
});
$app->put('/tasks/{id:[0-9]+}', function ($id) use($app) {
    $task = $app->request->getJsonRawBody()->task;
    $phql = "UPDATE Tasks SET name = :name:, short_description = :short:, long_description = :long:, started = :start:, completed = :complete: WHERE id = :id:";
    $status = $app->modelsManager->executeQuery($phql, ['name' => $task->name, 'short' => $task->shortDescription, 'long' => $task->longDescription, 'start' => $task->started, 'complete' => $task->completed, 'id' => $id]);
    $response = new \Phalcon\Http\Response();
    if ($status->success()) {
        $response->setJsonContent(['status' => 'OK']);
    }
});
$app->delete('/tasks/{id:[0-9]+}', function ($id) use($app) {
    $status = $app->modelsManager->executeQuery('DELETE FROM Tasks WHERE id = :id:', ['id' => $id]);
    $response = new \Phalcon\Http\Response();
    if ($status->success()) {
        $response->setJsonContent(['status' => 'OK']);
    }
    return $response;
});
/**
 * Ideas
 */
$app->get('/ideas', function () use($app) {
    $ideas = $app->modelsManager->executeQuery("SELECT * FROM Ideas");
    $data = new StdClass();
    $data->ideas = [];
    foreach ($ideas as $idea) {
        $data->ideas[] = ['id' => $idea->id, 'title' => $idea->title, 'body' => $idea->body, 'added' => $idea->added];
    }
    echo json_encode($data);
});
Пример #3
0
<?php

use app\controllers\AuthController, app\models\feeds, app\models\feedcomments, app\models\friends, app\models\feedfollows, app\models\metafriends, app\models\notifications, app\models\profiles, app\models\users, app\models\privacy, app\models\embeds, app\models\photos, app\models\photoalbums, app\models\photocomments, app\models\phototaggroups, app\controllers\NotificationController, app\library\session\userSessions, app\library\fs\fileStorage as fs;
/*
 * Micro doesn't support any headers (ex: cookies and redirection)
 */
$app = new \Phalcon\Mvc\Micro($di);
$app->get('/ajax/test', function () {
    return 'Powered By Phalcon API';
});
$app->post('/ajax/test', function () {
    return 'Powered By Phalcon API';
});
$app->delete('/ajax/test', function () {
    return 'Powered By Phalcon API';
});
$app->post('/ajax/recover', function () use($app) {
    $mongo = $app->getDI()->getShared('mongo');
    $json = $app->request->getJsonRawBody();
    $user = $mongo->users->find(array('email' => $json->email), array('email' => 1));
    $user = iterator_to_array($user, false);
    if (count($user) > 0) {
        $app->response->setJsonContent(array('success' => true));
    } else {
        $app->response->setJsonContent(array('success' => false, 'message' => "Email doesn't exist."));
    }
    $app->response->send();
});
$app->put('/ajax/recover/change', function () use($app) {
    $mongo = $app->getDI()->getShared('mongo');
});
Пример #4
-1
<?php

$app = new Phalcon\Mvc\Micro();
//Retrieves all robots
$app->get('/api/robots', function () {
});
//Searches for robots with $name in their name
$app->get('/api/robots/search/{name}', function ($name) {
});
//Retrieves robots based on primary key
$app->get('/api/robots/{id:[0-9]+}', function ($id) {
});
//Adds a new robot
$app->post('/api/robots', function () {
});
//Updates robots based on primary key
$app->put('/api/robots/{id:[0-9]+}', function () {
});
//Deletes robots based on primary key
$app->delete('/api/robots/{id:[0-9]+}', function () {
});
$app->handle();