Example #1
0
$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));
});
return $app;
Example #2
0
require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/CD.php";
require_once __DIR__ . "/../src/Artist.php";
session_start();
if (empty($_SESSION['cd_list'])) {
    $_SESSION['cd_list'] = 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('display.html.twig');
});
$app->post("/show", function () use($app) {
    $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);
Example #3
0
require_once __DIR__ . "/../src/CD.php";
session_start();
if (empty($_SESSION[collection])) {
    $_SESSION['collection'] = 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('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));
});