コード例 #1
0
 public function actionCreate()
 {
     if (!Yii::app()->user->checkAccess('addPlace')) {
         $this->_sendResponse(403);
         return;
     }
     $data = CJSON::decode(file_get_contents('php://input'));
     $place = new Places();
     $place->attributes = $data;
     if ($place->save()) {
         $this->_sendResponse(200, CJSON::encode($place));
     } else {
         $this->_sendResponse(500, CJSON::encode(array('message' => 'Could not save place', 'errors' => $place->getErrors())));
     }
 }
コード例 #2
0
ファイル: app.php プロジェクト: alexMcosta/places
<?php

require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/Places.php';
session_start();
if (empty($_SESSION['list_of_city_info'])) {
    $_SESSION['list_of_city_info'] = array();
}
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('content.html.twig', array('content' => Places::getAll()));
});
$app->post("/Place_Info", function () use($app) {
    $place = new Places($_POST['Place_Name'], $_POST['Stay_Time']);
    $place->save();
    return $app['twig']->render('create_place.html.twig', array('newplace' => $place));
});
return $app;
コード例 #3
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/Places.php";
session_start();
if (empty($_SESSION['list_of_places'])) {
    $_SESSION['list_of_places'] = array();
}
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('places.html.twig', array('places' => Places::getAll()));
});
$app->post("/places", function () use($app) {
    $places = new Places($_POST['place'], $_POST['duration']);
    $places->save();
    return $app['twig']->render('create_place.html.twig', array('newplace' => $places));
});
$app->post("/delete_place", function () use($app) {
    Places::deleteAll();
    return $app['twig']->render('delete_place.html.twig');
});
return $app;