$data = $em->find('model\\' . ucfirst($entity), $id); if ($data === null) { return new Response('Data not found', 404, array('Content-Type' => 'text/json')); } return new Response($data->toJson()); }); $app->post('/{entity}', function ($entity, Request $request) use($app, $em, $filter) { // Get POST data or 400 HTTP response if (!($data = $request->get($entity))) { return new Response('Missing parameters.', 400, array('Content-Type' => 'text/json')); } // Persist data to the database $entityName = 'model\\' . ucfirst($entity); $entity = new $entityName(); $entity->set($data); $entity->setCreated(new \DateTime("now")); //valid entity if (count($app['validator']->validate($entity)) > 0) { return new Response('Invalid parameters.', 400, array('Content-Type' => 'text/json')); } //Filter entity $filter->filterEntity($entity); $em->persist($entity); $em->flush(); return new Response($entity->toJson()); }); $app->put('/{entity}/{id}', function ($entity, $id, Request $request) use($app, $em, $filter) { if (!($data = $request->get($entity))) { return new Response('Missing parameters.', 400, array('Content-Type' => 'text/json')); } if (!($entity = $em->find('model\\' . ucfirst($entity), $id))) { return new Response('Not found.', 404, array('Content-Type' => 'text/json'));
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Contact.php"; session_start(); if (empty($_SESSION['list_of_contacts'])) { $_SESSION['list_of_contacts'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //this is the home page at contacts.html.twig $app->get("/", function () use($app) { return $app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll())); }); //this is the page where contacts are created & posted $app->post("/contacts", function () use($app) { $contact = new Contact($_POST['name'], $_POST['number'], $_POST['address']); $contact->save(); return $app['twig']->render('create_contacts.html.twig', array('newcontact' => $contact)); }); //this is the page where contacts are deleted $app->post("delete_contacts", function () use($app) { Contact::deleteAll(); return $app['twig']->render('delete_contacts.html.twig'); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Contact.php"; session_start(); //creates 'list_of_contacts' array if SESSION is empty if (empty($_SESSION['list_of_contacts'])) { $_SESSION['list_of_contacts'] = array(); } $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //root or homepage route $app->get("/", function () use($app) { return $app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll())); }); //saves a new contact and routes the user to /create_contact $app->post("/create_contact", function () use($app) { $contact = new Contact($_POST['create_name'], $_POST['create_phone'], $_POST['create_address']); $contact->save(); return $app['twig']->render('create_contact.html.twig', array('contacts' => Contact::getAll())); }); //deletes ALL contacts and routes user to /delete_contacts $app->post('/delete_contacts', function () use($app) { Contact::deleteAll(); return $app['twig']->render('delete_contacts.html.twig'); }); return $app;
// link to autoload and CONTACT CLASS require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Contact.php"; // needed to start the session session_start(); // load list of contacts if (empty($_SESSION['list_of_contacts'])) { $_SESSION['list_of_contacts'] = array(); } //load silex and turn on debug $app = new Silex\Application(); $app['debug'] = true; // needed for twig $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); // used to link to home page $app->get('/', function () use($app) { // get all conacts via twig return $app['twig']->render('contacts.html.twig', array('contacts' => Contact::getAll())); }); //post a new contact $app->post('/create_contact', function () use($app) { $contact = new Contact($_POST['name'], $_POST['phone'], $_POST['address']); $contact->save(); return $app['twig']->render('create_contact.html.twig', array('newcontact' => $contact)); }); // delte a contact $app->post('/delete_contacts', function () use($app) { Contact::deleteALL(); return $app['twig']->render('delete_contacts.html.twig'); }); return $app;
return $app->json($clientDetails); }); $app->put('/client/{clientId}', function (Request $request, $clientId) use($app, $DataProvider) { $clientDetails = $DataProvider->getClient($clientId); if (!$clientDetails) { return $app->json(['errorMessage' => 'Client Not Found'], 404); } $updateData = $DataProvider->getRequestData(); $result = $DataProvider->updateClient($clientId, $updateData); return $app->json(['message' => 'Client updated!']); }); $app->post('/client', function (Request $request) use($app, $DataProvider) { $insertData = $DataProvider->getRequestData(); $newClientId = $DataProvider->saveNewClient($insertData); if (false == $newClientId) { return $app->json(['errorMessage' => 'Can not insert user'], 500); } $clientDetails = $DataProvider->getClient($newClientId); return $app->json(['message' => 'Client created!', 'client' => $clientDetails]); }); $app->delete('/client/{clientId}', function (Request $request, $clientId) use($app, $DataProvider) { $DataProvider->deleteClient($clientId); return $app->json(['message' => 'Client deleted!']); }); /*======================================= = COMPANY SECTORS = =======================================*/ $app->get('/company-sectors', function () use($app, $DataProvider) { $sectors = $DataProvider->getSectors(); return $app->json($sectors); });
$app['debug'] = true; $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); session_start(); if (empty($_SESSION['list_of_cars'])) { $porsche = new Car("2014 Porsche 911", 114991, 7864, "images/porsche.jpg"); $ford = new Car("2011 Ford F450", 55995, 14241, "images/ford.jpg"); $lexus = new Car("2013 Lexus RX 350", 44700, 20000, "images/lexus.jpg"); $mercedes = new Car("Mercedes Benz CLS550", 39900, 37979, "images/mercedes.jpg"); $cars = array($porsche, $ford, $lexus, $mercedes); $_SESSION['list_of_cars'] = $cars; } $app->get("/", function () use($app) { $cars = $_SESSION['list_of_cars']; return $app['twig']->render('cars.html.twig', array('cars' => $cars)); }); $app->post("/create_cars", function () use($app) { $car = new Car($_POST['make'], $_POST['miles'], $_POST['price'], $_POST['image']); $car->save(); return $app['twig']->render('create_cars.html.twig', array('car' => $car)); }); $app->post("/search_car", function () use($app) { $cars_matching_search = array(); foreach ($_SESSION['list_of_cars'] as $car) { if ($car->worthBuying($_POST["price"], $_POST["miles"])) { array_push($cars_matching_search, $car); } } return $app['twig']->render('search_car.html.twig', array('cars_matching_search' => $cars_matching_search)); }); return $app;
$app['debug'] = true; $server = 'mysql:host=localhost;dbname=shoes'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); use Symfony\Component\HttpFoundation\Request; Request::enableHttpMethodParameterOverride(); //Routes $app->get('/', function () use($app) { return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); $app->post('/add_store', function () use($app) { $id = null; $store_name = $_POST['store_name']; $new_store = new Store($store_name, $id); $new_store->save(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); $app->post('/delete_stores', function () use($app) { Store::deleteAll(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); $app->post('/add_brand', function () use($app) { $id = null; $name = $_POST['brand_name']; $new_brand = new Brand($name, $id); $new_brand->save(); return $app['twig']->render('index.html.twig', array('stores' => Store::getAll(), 'brands' => Brand::getAll())); }); $app->post('/delete_brands', function () use($app) {
if (!$postToDisplay) { $app->abort(404, 'The article could not be found'); } return $app['twig']->render('post_single.html.twig', array('post' => $postToDisplay)); })->assert('post_id', '\\d+')->bind('post_single'); $app->get('/post/new', function () use($app) { $authorModel = new Author($app['db']); $authorsToDisplay = $authorModel->getAll(); return $app['twig']->render('post_new.html.twig', array('authors' => $authorsToDisplay)); })->bind('post_new'); $app->post('/post/add', function (Request $request) use($app) { $postModel = new Post($app['db']); $authorId = $request->request->get('author_id'); if (!isset($authorId)) { $app->abort(404, 'Author has to be selected. Go back and select author'); } $title = $request->request->get('title'); $message = $request->request->get('message'); $postModel->set($title, $message, $authorId); return $app->redirect($app["url_generator"]->generate("post_index")); })->bind('post_add'); $app->get('/authors', function () use($app) { $authorModel = new Author($app['db']); $authorsToDisplay = $authorModel->getAll(); return $app['twig']->render('author_index.html.twig', array('authors' => $authorsToDisplay)); })->bind('author_index'); $app->get('/author/{author_id}', function ($author_id) use($app) { $authorModel = new Author($app['db']); $authorToDisplay = $authorModel->get($author_id); if (!$authorToDisplay) { $app->abort(404, 'The article could not be found');
} }); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__)); $app->register(new Silex\Provider\ServiceControllerServiceProvider()); $app->register(new Shop\Database\DatabaseServiceProvider()); $app['illuminate.capsule']->bootEloquent(); $app['illuminate.capsule']->setAsGlobal(); $app['db.controller'] = $app->share(function () use($app) { return new Shop\Database\DBController($app, new \Shop\Database\Schema()); }); $app['db.controller']->createDB(); $app['home.controller'] = $app->share(function () use($app) { return new Shop\Home\HomeController($app); }); $app['products.controller'] = $app->share(function () use($app) { return new Shop\Products\ProductsController($app, $app['request'], new Shop\Products\ProductModel()); }); $app->get('/', 'home.controller:index'); $app->get('/products', 'products.controller:index'); $app->put('/products/{id}', 'products.controller:update'); $app->post('/products', 'products.controller:insert'); $app->delete('/products/{id}', 'products.controller:delete'); $app->post('/admin', function () use($app) { $admin = (require_once $app['base_dir'] . '/backend/config/admin.php'); $input = $app['request']->request->all(); if ($admin['username'] == $input['username'] && $admin['password'] == $input['password']) { return new Symfony\Component\HttpFoundation\Response(200); } // return new Symfony\Component\HttpFoundation\Response(500); }); $app->run();
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../City.php"; session_start(); if (empty($_SESSION['list_of_cities'])) { $_SESSION['list_of_cities'] = 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('cities.html.twig', array('cities' => City::getAll())); }); $app->post("/cities", function () use($app) { $city = new City($_POST['description'], $_POST['landmark']); ///connects to label id on cities.html.twig $city->save(); return $app['twig']->render('create_city.html.twig', array('newcity' => $city)); }); $app->post("/delete_cities", function () use($app) { City::deleteAll(); return $app['twig']->render('delete_cities.html.twig'); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Task.php"; session_start(); if (empty($_SESSION['list_of_tasks'])) { $_SESSION['list_of_tasks'] = 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('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->post("/tasks", function () use($app) { $task = new Task($_POST['description']); $task->save(); return $app['twig']->render('create_task.html.twig', array('newtask' => $task)); }); $app->post("/delete_tasks", function () use($app) { Task::deleteAll(); return $app['twig']->render('delete_tasks.html.twig'); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Place.php"; session_start(); if (empty($_SESSION['list_of_place'])) { $_SESSION['list_of_place'] = 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' => Place::getAll())); }); $app->post("/places", function () use($app) { $place = new Place($_POST['name'], $_POST['picture'], $_POST['time']); $place->save(); return $app['twig']->render('create_place.html.twig', array('newplace' => $place)); }); $app->post("/delete_places", function () use($app) { Place::deleteAll(); return $app['twig']->render('delete_places.html.twig'); }); $app->post("/", function () use($app) { Place::deleteONE($_POST['remove']); return $app['twig']->render('places.html.twig', array('places' => Place::getAll())); }); return $app;
} $app = new Silex\Application(); //Twig Path $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //Route and Controller $app->get("/", function () use($app) { return $app['twig']->render('carsearch.html.twig'); }); //Gets the user input from add a car $app->post("/added", function () use($app) { // $car_make = $_POST['car_make']; // $car_price = $_POST['car_price']; // $car_miles = $_POST['car_miles']; // $car_image = $_POST['car_image']; //$cars = Car::getAll(); $newcar = array(); $newcar = new Car($_POST['car_make'], $_POST['car_price'], $_POST['car_miles'], $_POST['car_image']); $newcar->save(); //array_push($newcar, $cars); //$cars->save(); return $app['twig']->render('addcar.html.twig', array('addedcar' => $newcar)); }); //$_POST['car_make'], $_POST['car_price'], $_POST['car_miles'], $_POST['car_image'] // $added_car = array(); // for($i = 0; $i < 10; $i++) { // $newcar = "newcar_$i"; // $$newcar = // $added_car = array($newcar); // //$added_car->savecar(); // } //
require_once __DIR__ . "/../src/Course.php"; $app = new Silex\Application(); $app['debug'] = true; $server = 'mysql:host=localhost;dbname=university'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); use Symfony\Component\HttpFoundation\Request; Request::enableHttpMethodParameterOverride(); //Home $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->post("/delete_courses", function () use($app) { Course::deleteAll(); return $app['twig']->render('index.html.twig'); }); //Courses $app->get("/courses", function () use($app) { return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll())); }); $app->post("/courses", function () use($app) { $course = new Course($_POST['name'], $_POST['number']); $course->save(); return $app['twig']->render('courses.html.twig', array('courses' => Course::getAll())); }); $app->get("/courses/{id}", function ($id) use($app) { $course = Course::find($id); return $app['twig']->render('course.html.twig', array('course' => $course, 'students' => $course->getStudents(), 'all_students' => Student::getAll())); }); $app->get("/courses/{id}/edit", function ($id) use($app) {
<?php namespace app; $app = new \Silex\Application(); $app->register(new \Silex\Provider\SessionServiceProvider()); $def = realpath(__DIR__ . '/../vendor/behat/mink/tests/Behat/Mink/Driver/web-fixtures'); $ovr = realpath(__DIR__ . '/web-fixtures'); $cbk = function ($file) use($app, $def, $ovr) { $file = str_replace('.file', '.php', $file); $path = file_exists($ovr . '/' . $file) ? $ovr . '/' . $file : $def . '/' . $file; $resp = null; ob_start(); include $path; $content = ob_get_clean(); if ($resp) { if ('' === $resp->getContent()) { $resp->setContent($content); } return $resp; } return $content; }; $app->get('/{file}', $cbk); $app->post('/{file}', $cbk); $app['debug'] = true; $app['exception_handler']->disable(); $app['session.test'] = true; return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Place.php"; session_start(); if (empty($_SESSION['list_of_places'])) { $_SESSION['list_of_places'] = 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('places.html.twig', array('places' => Place::getAll())); }); $app->post("/places", function () use($app) { $place = new Place($_POST['img_path'], $_POST['place'], $_POST['desc']); $place->save(); return $app['twig']->render('create_place.html.twig', array('newplace' => $place)); }); $app->post("/delete_places", function () use($app) { Place::deleteAll(); return $app['twig']->render('delete_places.html.twig'); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Place.php"; session_start(); if (empty($_SESSION['list_of_places'])) { $_SESSION['list_of_places'] = 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('places.html.twig', array('places' => Place::getAll())); }); $app->post("/places", function () use($app) { $place = new Place($_POST['city']); $place->save(); return $app['twig']->render('create_place.html.twig', array('newplace' => $task)); }); return $app;
// Routes $app->post('/login', function(Request $request) use($users, $privateKey) { $name = $request->get('name'); $user = $users->findOne(['name' => $name]); $password = $request->get('password'); if (null === $user || $password !== $user['password']) { throw new HttpException(Response::HTTP_FORBIDDEN, 'Invalid username or password.'); } // Generate new JSON Web Token. $builder = new JWT\Builder(); $builder ->setNotBefore(time()) ->setIssuer($request->getSchemeAndHttpHost()) ->setId($user['_id']->{'$id'}) ; foreach (['name', 'email', 'given_name', 'family_name', 'email_verified', 'gender'] as $field) { $builder->set($field, $user[$field]); } $builder->sign(new JWT\Signer\Rsa\Sha256(), $privateKey); $token = $builder->getToken(); return new Response($token, 200, ['Access-Control-Allow-Origin' => '*', 'Content-Type' => 'application/jwt']); }); $app->get('/images', function(Request $request) use($app, $images) { $image = $images->find()->sort(['date' => -1]);
$app->post('/', function (Request $request) use($app) { // Handle Olark webhook $data = json_decode($request->request->get('data'), true); // Stop if visitor email not found if (!isset($data['visitor']['emailAddress'])) { return new JsonResponse(['success' => false, 'error' => 'Visitor email is required']); } // Build conversion_messages $conversionMessages = ''; $offline = false; // If visitor full name not defined if (!isset($data['visitor']['fullName'])) { $data['visitor']['fullName'] = 'Visitor'; } foreach ($data['items'] as $item) { if ($item['kind'] == 'OfflineMessage') { $offline = true; } // If nickname not provided if (!isset($item['nickname'])) { // If this is message to visitor or message to operator if (in_array($item['kind'], ['MessageToOperator', 'OfflineMessage'])) { // ~> Nick name is visitor full name $item['nickname'] = $data['visitor']['fullName']; } else { // Else // ~> Nick name is operator (Operator always has nick name) $item['nickname'] = 'Operator'; } } $conversionMessages .= $item['nickname'] . ": " . $item['body'] . PHP_EOL; } $data['conversionMessages'] = $conversionMessages; // If only offline message and this is not offline if ($app['offline_only'] && !$offline) { // ~> return false return new JsonResponse(['success' => false, 'error' => 'Not an offline message']); } $url = 'https://' . $app['freshdesk_api_key'] . ':X@' . $app['freshdesk_subdomain'] . '.freshdesk.com'; $conf = new Connection($url); $t = new Ticket($conf); //create new ticket $model = new TicketM(array('subject' => buildMessage($app['ticket_subject'], $data), 'description' => buildMessage($app['ticket_description'], $data), 'email' => $data['visitor']['emailAddress'])); //create new ticket, basic example $result = $t->createNewTicket($model); return new JsonResponse(['success' => $result != false]); });
$data = $music_site->search($request->query->all()); return $app['twig']->render($data['page'], $data['params']); }); $app->get('/{type}/{key}', function ($type, $key) use($app) { $music_site = new MusicSite(); $data = $music_site->getPage($type, $key); if (is_null($data)) { return $app->abort(404); } return $app['twig']->render($data['page'], $data['params']); }); //ADMIN $app->post('/connection', function (Request $request) use($app) { $pass = $request->get('pass'); if ($pass == "root") { $_SESSION['connected'] = true; } return $app->redirect($request->server->getHeaders()['REFERER']); }); $app->get('/disconnection', function () use($app) { session_destroy(); return $app->redirect(url); }); $app->get('/{type}/{key}/{action}', function ($type, $key, $action) use($app) { if (!$_SESSION['connected']) { return $app->abort(404); } $accepted = array('add', 'set'); if (!in_array($action, $accepted)) { return $app->abort(404); }
$pages = $snippets_model->get_pages_all($page); $cat_details = array('slug' => 'all', 'title' => 'All', 'count' => $snippets_model->get_snippets_count()); } else { $cat_details = $snippets_model->get_cat_details($category); $cat_details = $cat_details[0]; $snippets = $snippets_model->get_by_category($category, $page); $pages = $snippets_model->get_pages_by_category($cat_details['id'], $page); } $app["twig"]->addGlobal("actualPage", array("page" => "category", "category" => $category)); return $app['twig']->render('snippets.twig', array('snippets' => $snippets, "pages" => $pages, 'catdetails' => $cat_details)); })->value('page', 1)->bind('category'); $app->post('/add_snippet', function (Request $request) use($app, $snippets_model) { $title = $request->get('title'); $message = $request->get('message'); $category = $request->get('category'); if (empty($title) || empty($message) || empty($category)) { die('error'); } $snippets_model->add_snippet($title, $message, $category); die('ok'); })->bind('add_snippet'); $app->get('/about', function () use($app, $snippets_model) { $app["twig"]->addGlobal("actualPage", array("page" => "about")); return $app['twig']->render('about.twig'); })->bind('about'); // contact form $app->get('/contact', function () use($app, $snippets_model) { $app["twig"]->addGlobal("actualPage", array("page" => "contact")); return $app['twig']->render('contact.twig'); })->bind('contact'); $app->post('/contact_submit', function (Request $request) use($app, $snippets_model) { $title = $request->get('title');
<?php require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../src/rps.php'; // session_start(); // if (empty($_SESSION['list_of_anagrams'])) { // $_SESSION['list_of_anagrams'] = 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('rps.html.twig'); }); $app->post("/results", function () use($app) { $new_RockPaperScissors = new RockPaperScissors(); $result = $new_RockPaperScissors->playGame($_POST['player1'], $_POST['player2']); return $app['twig']->render('result.html.twig', array('new_RockPaperScissors' => $result)); }); return $app;
return $app['twig']->render('index.html.twig', array('categories' => Category::getAll(), 'tasks' => Task::getAll())); }); $app->get("/tasks", function () use($app) { return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->get("/categories", function () use($app) { return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->get("/categories/{id}", function ($id) use($app) { $category = Category::find($id); return $app['twig']->render('category.html.twig', array('category' => $category, 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->post("/tasks", function () use($app) { $description = $_POST['description']; $due_date = $_POST['due_date']; $task = new Task($description, $due_date); $task->save(); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->get("/tasks/{id}", function ($id) use($app) { $task = Task::find($id); return $app['twig']->render('task.html.twig', array('task' => $task, 'categories' => $task->getCategories(), 'all_categories' => Category::getAll())); }); $app->post("/add_tasks", function () use($app) { $category = Category::find($_POST['category_id']); $task = Task::find($_POST['task_id']); $category->addTask($task); return $app['twig']->render('category.html.twig', array('category' => $category, 'categories' => Category::getAll(), 'tasks' => $category->getTasks(), 'all_tasks' => Task::getAll())); }); $app->get("/tasks/{id}/edit", function ($id) use($app) { $task = Task::find($id);
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/Place.php"; session_start(); if (empty($_SESSION['places_list'])) { $_SESSION['places_list'] = 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('list_of_places.html.twig', array('places' => Place::getAll())); }); $app->post("/make_place", function () use($app) { $place = new Place($_POST['city'], $_POST['image'], $_POST['stayLength']); $place->save(); return $app['twig']->render('make_place.html.twig', array('newplace' => $place)); }); $app->post("/delete_place", function () use($app) { Place::deleteAll(); return $app['twig']->render('delete_place.html.twig'); }); return $app;
Request::enableHttpMethodParameterOverride(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); //GETS $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->get("/stores", function () use($app) { return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); $app->get("/brands", function () use($app) { return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll())); }); //POSTS $app->post("/stores", function () use($app) { $store = new Store($_POST['store_name']); $store->save(); return $app['twig']->render('stores.html.twig', array('stores' => Store::getAll())); }); $app->post("/brands", function () use($app) { $brand = new Brand($_POST['brand_name']); $brand->save(); return $app['twig']->render('brands.html.twig', array('brands' => Brand::getAll())); }); //EDIT GETS $app->get("/stores/{id}", function ($id) use($app) { $store = Store::find($id); return $app['twig']->render('store.html.twig', array('store' => $store, 'brands' => $store->getBrands(), 'all_brands' => Brand::getAll())); }); $app->get("/brands/{id}", function ($id) use($app) { $brand = Brand::find($id); return $app['twig']->render('brand.html.twig', array('brand' => $brand, 'stores' => $brand->getStores(), 'all_stores' => Store::getAll()));
} $app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); /* CAR_FORM.HTML.TWIG - Home route */ $app->get("/", function () use($app) { return $app['twig']->render('car_form.html.twig', array('cars' => Car::getAll())); }); /* END CAR_FORM.HTML.TWIG */ /* START VIEW_CAR.HTML.TWIG */ $app->get("/view_car", function () use($app) { $cars = Car::getAll(); $cars_matching_search = array(); foreach ($cars as $car) { if ($car->worthBuying($_GET["price"]) && $car->worthBuying($_GET["miles"])) { array_push($cars_matching_search, $car); } } return $app['twig']->render('view_car.html.twig', array('cars' => $cars_matching_search)); }); /* END VIEW_CAR.HTML.TWIG */ /* BEGIN SELL_CAR.HTML.TWIG */ $app->get("/sell_car", function () use($app) { return $app['twig']->render('sell_car.html.twig'); }); $app->post("/car_added", function () use($app) { $car = new Car($_POST['make'], $_POST['price'], $_POST['miles'], $_POST['photo']); $car->save(); return $app['twig']->render('car_added.html.twig', array('newcar' => $car)); }); /* END SELL_CAR.HTML.TWIG */ return $app;
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); use Symfony\Component\HttpFoundation\Request; Request::enableHttpMethodParameterOverride(); // HOME PAGE - DISPLAYS ADMIN LINK AND PATRON LINK $app->get('/', function () use($app) { return $app['twig']->render('index.html.twig'); }); // ADMIN PAGE - DISPLAYS BOOK CATALOG $app->get("/main_admin", function () use($app) { $books = Book::getAll(); $authors = Author::getAll(); return $app['twig']->render("main_admin.html.twig", array('books' => $books, 'authors' => $authors)); }); $app->post("/delete_books", function () use($app) { $GLOBALS['DB']->exec("DELETE FROM books;"); Book::deleteAll(); return $app['twig']->render('main_admin.html.twig', array('books' => Book::getAll())); }); //add new book with author $app->post("/book_added", function () use($app) { // create new book from user entry "add book" $title = $_POST['title']; $new_book = new Book($title); $new_book->save(); // create new author from user entry "add book" // possibly check that the author is already in the database - NOT NOW $name_array = explode(',', $_POST['name']); foreach ($name_array as $name) { $new_author = new Author($name); $new_author->save(); $new_book->addAuthor($new_author);
$app['debug'] = true; $server = 'mysql:host=localhost;dbname=best_restaurant'; $username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); use Symfony\Component\HttpFoundation\Request; Request::enableHttpMethodParameterOverride(); //landing page which displays all cuisines $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); //creates a new cuisine, saves it to the database, and displays it on the homepage $app->post('/cuisines', function () use($app) { $cuisine = new Cuisine($_POST['name']); $cuisine->save(); return $app['twig']->render('index.html.twig', array('cuisines' => Cuisine::getAll())); }); //brings user to specific cuisine page $app->get("/cuisines/{id}", function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisines.html.twig', array('cuisines' => $cuisine, 'restaurants' => $cuisine->getRestaurants())); }); //brings user to a page that allows a specific cuisine to be edited $app->get('/cuisines/{id}/edit', function ($id) use($app) { $cuisine = Cuisine::find($id); return $app['twig']->render('cuisine_edit.html.twig', array('cuisines' => $cuisine)); }); //posts edited data to the database to update a property in the existing cuisine $app->patch("/cuisines/{id}", function ($id) use($app) { $name = $_POST['name'];
$username = '******'; $password = '******'; $DB = new PDO($server, $username, $password); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get("/", function () use($app) { return $app['twig']->render('index.html.twig'); }); $app->get("/tasks", function () use($app) { return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->get("/categories", function () use($app) { return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->post("/tasks", function () use($app) { $task = new task($_POST['description']); $task->save(); return $app['twig']->render('tasks.html.twig', array('tasks' => Task::getAll())); }); $app->post("/delete_tasks", function () use($app) { Task::deleteAll(); return $app['twig']->render('index.html.twig'); }); $app->post("/categories", function () use($app) { $category = new Category($_POST['name']); $category->save(); return $app['twig']->render('categories.html.twig', array('categories' => Category::getAll())); }); $app->post("/delete_categories", function () use($app) { Category::deleteAll(); return $app['twig']->render('index.html.twig'); });
$app->post('/findmatches', function (\Silex\Application $app) { try { $post = json_decode(file_get_contents("php://input"), true); if (!isset($post['steam'])) { return new \Symfony\Component\HttpFoundation\JsonResponse('Provide at least one player!'); } $users = $post['steam']; if (count($users) == 1) { $id = SteamId::create(current($users)); /** * @var $singleGames SteamGame[] */ $singleGames = $id->getGames(); $localMultiplayerGames = array_filter($singleGames, function ($game) { return SteamCache::hasLocalMultiplayer($game->getAppId()); }); if (count($localMultiplayerGames) == 0) { throw new Exception("No games found"); } $randomGame = $localMultiplayerGames[array_rand($localMultiplayerGames)]; return new \Symfony\Component\HttpFoundation\JsonResponse(array('status' => 'success', 'response' => array('id' => $randomGame->getAppId(), 'name' => $randomGame->getName(), 'store' => $randomGame->getStoreUrl(), 'image' => $randomGame->getLogoUrl()))); } $gameCollections = []; foreach ($users as $user) { $id = SteamId::create($user); $gameCollections[] = $id->getGames(); } $gameCollections[] = function ($a, $b) { /** * @var $a SteamGame * @var $b SteamGame */ if ($a instanceof SteamGame && $b instanceof SteamGame) { if ($a->getAppId() === $b->getAppId()) { if (SteamCache::hasOnlineMultiplayer($a->getAppId())) { return 0; } } } return 1; }; $games3 = call_user_func_array('array_uintersect_assoc', $gameCollections); if (count($games3) == 0) { throw new Exception("No games found"); } $randomGame = $games3[array_rand($games3)]; return new \Symfony\Component\HttpFoundation\JsonResponse(array('status' => 'success', 'response' => array('id' => $randomGame->getAppId(), 'name' => $randomGame->getName(), 'store' => $randomGame->getStoreUrl(), 'image' => $randomGame->getLogoUrl()))); } catch (Exception $e) { return new \Symfony\Component\HttpFoundation\JsonResponse(array('status' => 'error', 'response' => $e->getMessage())); } });