$cd = new CD($_POST['title'], new Artist($_POST['artist'])); $cd->save(); return $app['twig']->render('display.html.twig', array('cds' => CD::getAll())); }); $app->post("/clear", function () use($app) { CD::reset(); return $app['twig']->render('display.html.twig', array('cds' => CD::getAll())); }); $app->get("/cd_search", function () use($app) { $cds = CD::getAll(); $search_return = array(); $search = strtolower($_GET['artist']); foreach ($cds as $cd) { $this_artist = $cd->getArtist(); $artist = strtolower($this_artist->getName()); if ($cd->matchArtist($artist, $search)) { array_push($search_return, $cd); } } return $app['twig']->render('displaysearch.html.twig', array('cds' => $search_return)); }); $app->get("/new", function () use($app) { return $app['twig']->render('new_cd.html.twig'); }); $app->get("/list", function () use($app) { return $app['twig']->render('display.html.twig', array('cds' => CD::getAll())); }); $app->get("/search", function () use($app) { return $app['twig']->render('searchbyartist.html.twig'); }); return $app;
<?php require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../src/CD.php'; session_start(); if (empty($_SESSION['list_of_cds'])) { $_SESSION['list_of_cds'] = 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('home.html.twig'); }); $app->get('/new_cd', function () use($app) { return $app['twig']->render('new_cd.html.twig'); }); $app->post('/cd_inserted', function () use($app) { $cd = new CD($_POST['album'], $_POST['artist']); $cd->save(); $cd_list = CD::getAll(); return $app['twig']->render('home.html.twig', array('cds' => $cd_list)); }); return $app;
<?php require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/CD.php"; session_start(); if (empty($_SESSION['list_of_artists'])) { $_SESSION['list_of_artists'] = array(); } $app = new Silex\Application(); $app['debug'] = false; $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . "/../views")); $app->get("/", function () use($app) { return $app['twig']->render('home.html.twig', array('artists' => CD::getAll())); }); $app->get('/add_cd', function () use($app) { return $app['twig']->render('add_cd.html.twig'); }); $app->post('/added', function () use($app) { $cd = new CD($_POST['artist']); $cd->save(); return $app['twig']->render('added_cd.html.twig'); }); return $app;
$_SESSION['list_of_cds'] = 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('main_page.html.twig', array('all_cds' => CD::getAll())); }); $app->get("/add_form", function () use($app) { return $app['twig']->render('add_form.html.twig'); }); $app->get("/search_form", function () use($app) { return $app['twig']->render('search_form.html.twig'); }); $app->get("/search_results", function () use($app) { $allCD = CD::getAll(); $foundCD = array(); $artistSearch = $_GET['artist']; foreach ($allCD as $cd) { $actualCD = strtolower($cd->getArtist()); $actualSearch = strtolower($artistSearch); if (strpos($actualCD, $actualSearch) != false) { array_push($foundCD, $cd); } } return $app['twig']->render('search_results.html.twig', array('found' => $foundCD)); }); $app->post("/add", function () use($app) { $newCD = new CD($_POST['artist'], $_POST['album'], $_POST['cover']); $newCD->save(); return $app['twig']->render('added.html.twig', array('newCd' => $newCD));
$app = new Silex\Application(); $app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views')); $app->get('/', function () use($app) { return $app['twig']->render('cds.html.twig', array('albums' => CD::getAll())); }); $app->get('/new_cd', function () use($app) { return $app['twig']->render('new_cd.html.twig'); }); $app->post('/new_cd', function () use($app) { $album = new CD($_POST['title'], $_POST['artist']); $album->save(); return $app['twig']->render('cds.html.twig', array('albums' => CD::getAll())); }); $app->get('/searchbyartist', function () use($app) { return $app['twig']->render('searchbyartist.html.twig'); }); $app->get('/search_results', function () use($app) { $albums = CD::getAll(); $catalog = array(); foreach ($albums as $album) { if ($album->artistSearch($_GET['artist_search'])) { array_push($catalog, $album); } } return $app['twig']->render('search_results.html.twig', array('catalog' => $catalog)); }); $app->post('/delete_cds', function () use($app) { CD::deleteAll(); return $app['twig']->render('delete_cds.html.twig'); }); return $app;
require_once __DIR__ . "/../vendor/autoload.php"; require_once __DIR__ . "/../src/CD.php"; session_start(); if (empty($_SESSION['cd_list'])) { $_SESSION['cd_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('cd.html.twig', array('cds' => CD::getAll())); }); //this should be a GET, not a post!!! $app->get("/cds", function () use($app) { return $app['twig']->render('new_cd.html.twig'); }); $app->post("/", function () use($app) { //error undefined index: artist??? $cd = new CD($_POST['artist'], $_POST['album']); $cd->save(); return $app['twig']->render('cd.html.twig', array('cds' => CD::getAll())); }); $app->post("delete_cd", function () use($app) { CD::deleteAll(); return $app['twig']->render('delete_cd.html.twig'); }); $app->get("/searchbyartist", function () use($app) { $artist_matching_search = array(); CD::getAll(); return $app['twig']->render('searchbyartist.html.twig'); }); return $app;