本文整理汇总了PHP中Book::all方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::all方法的具体用法?PHP Book::all怎么用?PHP Book::all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$users = User::all();
$book_count = Book::all()->count();
$chapter_count = Chapter::all()->count();
return View::make('admin.admin_panel', array('pageTitle' => 'Admin Panel', 'users' => $users, 'book_count' => $book_count, 'chapter_count' => $chapter_count));
}
示例2: sandbox
public static function sandbox()
{
// Testaa koodiasi täällä
//View::make('helloworld.html');
$torakat = Book::find(1);
$books = Book::all();
Kint::dump($books);
Kint::dump($torakat);
}
示例3: test_delete_by_find_all
public function test_delete_by_find_all()
{
$books = Book::all();
foreach ($books as $model) {
$model->delete();
}
$res = Book::all();
$this->assert_equals(0, count($res));
}
示例4: firstPageBooks
public static function firstPageBooks()
{
//now this method searches all the books just like "listingBooks" -method,
//but later on (when we have more books in the database), this method wants some
//subset of books (like every books that start with "s", or most favourite books or books selected by admin or...)
$books = Book::all();
// self::sort_books($books);
View::make('general/firstpage.html', array('books' => $books));
}
示例5: collections
public function collections()
{
$collection = Book::all();
//echo Pre::render($collection);
# The many faces of a Eloquent Collection object...
# Treat it like a string:
echo $collection;
# Treat it like an array:
//foreach($collection as $book) {
// echo $book['title']."<br>";
//}
# Treat it like an object:
//foreach($collection as $book) {
// echo $book->title."<br>";
//}
}
示例6: run
public function run()
{
$faker = Faker\Factory::create();
//getting all books from the table
$books = Book::all();
$isbn_list = array();
//getting all ISBNs into a single array
foreach ($books as $book) {
array_push($isbn_list, $book->isbn);
}
DB::table('library_books')->delete();
for ($i = 0; $i < 15; $i++) {
$fake_library_id = $faker->numberBetween(1, 10);
$fake_book_isbn = $faker->randomElement($isbn_list);
//checking for duplications
if (LibraryBooks::where('user_id', '=', $fake_library_id)->where('book_isbn', '=', $fake_book_isbn)->count() > 0) {
continue;
}
LibraryBooks::create(array('user_id' => $fake_library_id, 'book_isbn' => $fake_book_isbn, 'copies_no' => $faker->numerify('##')));
}
}
示例7: function
<?php
// Modelo de objetos que se corresponde con la tabla de MySQL
class Book extends \Illuminate\Database\Eloquent\Model
{
public $timestamps = false;
}
// Añadir el resto del código aquí
$app->get('/books', function () use($app) {
// Creamos un objeto collection + json con la lista de películas
// Obtenemos el objeto request, que representa la petición HTTP
$req = $app->request;
// Obtenemos la ruta absoluta de este recurso
$absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri();
// Obtenemos la lista de los libros de la base de datos y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP
$libros = json_decode(\Book::all());
$app->view()->setData(array('url' => $absUrl, 'items' => $libros));
// Mostramos la vista
$app->render('booklist_template.php');
});
/* Obtención de un libro en concreto */
$app->get('/books/:name', function ($name) use($app) {
// Creamos un objeto collection + json con el libro pasado como parámetro
// Obtenemos el objeto request, que representa la petición HTTP
$req = $app->request;
// Obtenemos la ruta absoluta de este recurso
$absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri();
// Obtenemos el libro de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP
$p = \book::find($name);
$libro = json_decode($p);
$app->view()->setData(array('url' => preg_replace('/' . preg_quote('/' . $name, '/') . '$/', '', $absUrl), 'item' => $libro));
示例8: testDeleteByFindAll
public function testDeleteByFindAll()
{
$books = Book::all();
foreach ($books as $model) {
$model->delete();
}
$res = Book::all();
$this->assertEquals(0, count($res));
}
示例9: home
public function home()
{
$rs = Book::all();
$data = $rs->toArray();
echo View::getView()->make('home', array('data' => $data))->render();
}
示例10: function
echo "[]";
}
});
$app->post('/books', function () use($app) {
$title = $app->request->post('title');
$author = $app->request->post('author');
$year = $app->request->post('year');
// Or create a new book
$book = new Book(array('title' => $title, 'author' => $author, 'year' => $year));
$book->save();
echo $book->toJson();
});
$app->delete('/books/:id', function ($book_id) use($app) {
$book = Book::find($book_id);
$book->delete();
$books = Book::all();
echo $books->toJson();
});
$app->put('/books/:id', function ($book_id) use($app) {
$title = $app->request->put('title');
$author = $app->request->put('author');
$year = $app->request->put('year');
$book = Book::find($book_id);
if ($book != null) {
$book->id = $book_id;
$book->title = $title;
$book->author = $author;
$book->year = $year;
$book->save();
echo $book->toJson() . $book_id . $title . $author . $year . $book->author . $book->id;
//http://stackoverflow.com/questions/23761425/get-put-params-with-slim-php
示例11: submit
public function submit()
{
$books = Book::all();
return $this->response->withCollection($books, new BookTransformer());
}
示例12: function
<?php
// Modelo de objetos que se corresponde con la tabla de MySQL
class Book extends \Illuminate\Database\Eloquent\Model
{
public $timestamps = false;
}
/* Obtención de la lista de libros */
$app->get('/books', function () use($app) {
// Creamos un objeto collection + json con la lista de libros
// Obtenemos el objeto request, que representa la petición HTTP
$req = $app->request;
// Obtenemos la ruta absoluta de este recurso
$absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri();
// Obtenemos la lista de librosde la base de datos y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP
$books = json_decode(\Book::all());
$app->view()->setData(array('url' => $absUrl, 'items' => $books));
// Mostramos la vista
$app->render('booklist_template.php');
});
/* Obtención de un libro en concreto */
$app->get('/books/:name', function ($name) use($app) {
// Creamos un objeto collection + json con la película pasada como parámetro
// Obtenemos el objeto request, que representa la petición HTTP
$req = $app->request;
// Obtenemos la ruta absoluta de este recurso
$absUrl = $req->getScheme() . "://" . $req->getHost() . $req->getRootUri() . $req->getResourceUri();
// Obtenemos la película de la base de datos a partir de su id y la convertimos del formato Json (el devuelto por Eloquent) a un array PHP
$p = \Book::find($name);
$libro = json_decode($p);
$app->view()->setData(array('url' => preg_replace('/' . preg_quote('/' . $name, '/') . '$/', '', $absUrl), 'item' => $libro));
示例13: index
/**
* Get all books
*
* @return Response
*/
public function index()
{
$books = Book::all();
return Response::json(['data' => $books]);
}
示例14: index
function index()
{
global $twig;
$books = new Book();
echo $twig->render('books_list.html', array('books' => $books->all()));
}
示例15: index
public static function index()
{
$books = Book::all();
Kint::dump($books);
View::make('book/index.html', array('books' => $books));
}