public function getIndex() { # Format and Query are passed as Query Strings $format = Input::get('format', 'html'); $query = Input::get('query'); $books = Book::search($query); # Decide on output method... # Default - HTML if ($format == 'html') { return View::make('book_index')->with('books', $books)->with('query', $query); } elseif ($format == 'json') { return Response::json($books); } elseif ($format == 'pdf') { return "This is the pdf (Coming soon)."; } }
foreach ($courses as $c) { echo $c->getDescription() . "\n"; } $c = new Course(); $c->setId(1); $c->load(); echo $c->getDescription() . "\n"; $students = $c->getStudents(); foreach ($students as $s) { echo $s->getName() . "\n"; } //SEARCH $p = new Person(); $p->setName('Mat'); $search = $p->search(); $search->orderBy('name'); $list = $search->execute(); foreach ($list as $p) { echo $p->getName() . "\n"; } //Recursive Search $c = new City(); $c->setName('San'); $p = new Person(); $p->setCity($c); $b = new Book(); $b->setAuthor($p); $list = $b->search()->execute(); foreach ($list as $b) { echo $b->getTitle() . "\n"; }
$title = $_POST['title']; $book->update($title); $authors = $book->getAuthors(); $copies = Copy::findCopies($id); return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $authors, 'all_authors' => Author::getAll(), 'copies' => $copies)); }); $app->post("/add_authors", function () use($app) { $book = Book::find($_POST['book_id']); $author = Author::find($_POST['author_id']); $book->addAuthor($author); $copies = Copy::findCopies($_POST['book_id']); return $app['twig']->render('book.html.twig', array('book' => $book, 'authors' => $book->getAuthors(), 'all_authors' => Author::getAll(), 'copies' => $copies)); }); //book search result page $app->get("/search_books", function () use($app) { $search = Book::search($_GET['search']); return $app['twig']->render('search_books.html.twig', array('search' => $search, 'search_book' => $_GET['search'])); }); //author search result page $app->get("/search_authors", function () use($app) { $search = Author::search($_GET['search']); return $app['twig']->render('search_authors.html.twig', array('search' => $search, 'search_author' => $_GET['search'])); }); //authors $app->get("/authors", function () use($app) { return $app['twig']->render('authors.html.twig', array('authors' => Author::getAll())); }); $app->get("/author/{id}", function ($id) use($app) { $author = Author::find($id); $book = $author->getAuthors(); return $app['twig']->render('author.html.twig', array('book' => $book, 'author' => $author));
/** * Process a book search * Called w/ Ajax */ public function postSearch() { if (Request::ajax()) { $query = Input::get('query'); # We're demoing two possible return formats: JSON or HTML $format = Input::get('format'); # Do the actual query $books = Book::search($query); # If the request is for JSON, just send the books back as JSON if ($format == 'json') { return Response::json($books); } elseif ($format == 'html') { $results = ''; foreach ($books as $book) { # Created a "stub" of a view called book_search_result.php; all it is is a stub of code to display a book # For each book, we'll add a new stub to the results $results .= View::make('book_search_result')->with('book', $book)->render(); } # Return the HTML/View to JavaScript... return $results; } } }