当前位置: 首页>>代码示例>>PHP>>正文


PHP Book::addAuthor方法代码示例

本文整理汇总了PHP中Book::addAuthor方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::addAuthor方法的具体用法?PHP Book::addAuthor怎么用?PHP Book::addAuthor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Book的用法示例。


在下文中一共展示了Book::addAuthor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: array

Request::enableHttpMethodParameterOverride();
$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("/librarian", function () use($app) {
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
$app->post("/librarian", function () use($app) {
    $title = $_POST['title'];
    $book = new Book($title);
    $book->save();
    $name = $_POST['author'];
    $author = new Author($name);
    $author->save();
    $book->addAuthor($author);
    $book->addCopy($_POST['copies']);
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll()));
});
$app->delete("/book/{id}/delete", function ($id) use($app) {
    $book = Book::find($id);
    $book->deleteBook();
    return $app['twig']->render('librarian.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
$app->get("/book/{id}/edit", function ($id) use($app) {
    $book = Book::find($id);
    return $app['twig']->render("edit_book.html.twig", array("book" => $book));
});
$app->patch("/book/{id}", function ($id) use($app) {
    $book = Book::find($id);
    if (!empty($_POST['title'])) {
开发者ID:bdspen,项目名称:library_day1,代码行数:31,代码来源:app.php

示例2: testGetAuthors

 function testGetAuthors()
 {
     //Arrange
     $book_title = "Snow Crash";
     $id = 1;
     $test_book = new Book($book_title, $id);
     $test_book->save();
     $author_name = "Super Dog";
     $id2 = 2;
     $test_author = new Author($author_name, $id2);
     $test_author->save();
     $author_name2 = "Neal Stephenson";
     $id3 = 3;
     $test_author2 = new Author($author_name2, $id3);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals($result, [$test_author, $test_author2]);
 }
开发者ID:kylepratuch,项目名称:library-1,代码行数:22,代码来源:BookTest.php

示例3: testGetAuthors

 function testGetAuthors()
 {
     //Arrange
     $id = null;
     $name = "A Series of Unfortunate Events";
     $test_book = new Book($id, $name);
     $test_book->save();
     $name2 = "Lemony Snicket";
     $test_author = new Author($id, $name2);
     $test_author->save();
     $test_book->addAuthor($test_author);
     $name3 = "J.R.R. Tolkien";
     $test_author2 = new Author($id, $name3);
     $test_author2->save();
     $test_book->addAuthor($test_author2);
     //Act
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals([$test_author, $test_author2], $result);
 }
开发者ID:kellimargaret,项目名称:2015.08.26.Library,代码行数:20,代码来源:BookTest.php

示例4: testDelete

 function testDelete()
 {
     //Arrange
     $author_name = "Stephen King";
     $id = 1;
     $test_author = new Author($author_name, $id);
     $test_author->save();
     $book_name = "Gattica";
     $id = 1;
     $test_book = new Book($book_name, $id);
     $test_book->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->deleteOne();
     //Assert
     $this->assertEquals([], $test_author->getBooks());
 }
开发者ID:kennygrage,项目名称:epicLibrary,代码行数:17,代码来源:BookTest.php

示例5: testGetAuthor

 function testGetAuthor()
 {
     //Arrange
     $title = "Grapes of Wrath";
     $test_book = new Book($title);
     $test_book->save();
     $first_name = "J.K.";
     $last_name = "Rowling";
     $test_author = new Author($first_name, $last_name);
     $test_author->save();
     $first_name2 = "John";
     $last_name2 = "Steinbeck";
     $test_author2 = new Author($first_name2, $last_name2);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $result = $test_book->getAuthor();
     //Assert
     $this->assertEquals([$test_author, $test_author2], $result);
 }
开发者ID:jtorrespdx,项目名称:library,代码行数:21,代码来源:BookTest.php

示例6: Book

 function test_addAuthor_getAuthors()
 {
     $title = "Three Blind Mice";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Chicken Dog";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $author_name = "Jimmy Neutron";
     $test_author = new Author($author_name);
     $test_author->save();
     $test_book->addAuthor($test_author);
     $result = $test_book->getAuthors();
     $this->assertEquals([$test_author], $result);
 }
开发者ID:juliocesardiaz,项目名称:Library,代码行数:15,代码来源:BookTest.php

示例7: testGetAuthors

 function testGetAuthors()
 {
     //Arrange
     $title = "Eat a Cupcake";
     $year_published = 1999;
     $id = null;
     $test_book = new Book($title, $year_published, $id);
     $test_book->save();
     $name = "Nathan Young";
     $test_author = new Author($name, $id);
     $test_author->save();
     $name2 = "Kyle Pratuch";
     $test_author2 = new Author($name2, $id);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $this->assertEquals([$test_author, $test_author2], $test_book->getAuthors());
 }
开发者ID:nathanhwyoung,项目名称:Library,代码行数:20,代码来源:BookTest.php

示例8: Book

 function test_getAuthors()
 {
     //Arrange
     $title = "dog book";
     $test_book = new Book($title);
     $test_book->save();
     $name = "William Wegman";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Bogus Dogtographer";
     $test_author2 = new Author($name2);
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $result = $test_book->getAuthors();
     $this->assertEquals([$test_author, $test_author2], $result);
 }
开发者ID:r-hills,项目名称:Library,代码行数:19,代码来源:BookTest.php

示例9: Book

 function test_deleteAllAuthors()
 {
     //Arrange
     $title = "Wesley Pong";
     $test_book = new Book($title);
     $test_book->save();
     $name = "History";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Lit";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Act
     $test_book->deleteAllAuthors();
     $result = $test_book->getAuthors();
     //Assert
     $this->assertEquals([], $result);
 }
开发者ID:jlbethel,项目名称:library-1,代码行数:20,代码来源:BookTest.php

示例10: Author

 function test_AddAuthor()
 {
     //Arrange
     $author_name = "Jack London";
     $test_author = new Author($author_name);
     $test_author->save();
     $title = "Sea Wolf";
     $test_book = new Book($title);
     $test_book->save();
     //Act
     $result = [$test_author];
     $test_book->addAuthor($test_author);
     //Assert
     $this->assertEquals($test_book->getAuthors(), $result);
 }
开发者ID:jlbethel,项目名称:Library,代码行数:15,代码来源:BookTest.php

示例11: testSearchByTitle

 function testSearchByTitle()
 {
     //Arrange
     $author_first = "J.K.";
     $author_last = "Rowling";
     $test_author = new Author($author_first, $author_last);
     $test_author->save();
     $author_first2 = "Stephen";
     $author_last2 = "King";
     $test_author2 = new Author($author_first2, $author_last2);
     $test_author2->save();
     $author_first3 = "John";
     $author_last3 = "Steinbeck";
     $test_author3 = new Author($author_first2, $author_last2);
     $test_author3->save();
     $title = "Grapes of Wrath";
     $test_book = new Book($title);
     $test_book->save();
     $test_book->addAuthor($test_author3);
     $title2 = "Harry Potter";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_book2->addAuthor($test_author);
     $title3 = "Evil Wrath";
     $test_book3 = new Book($title3);
     $test_book3->save();
     $test_book3->addAuthor($test_author2);
     $search_string = "Wrath";
     //Act
     $result = Book::searchByTitle($search_string);
     //Assert
     $this->assertEquals([$test_book, $test_book3], $result);
 }
开发者ID:alexMcosta,项目名称:library2,代码行数:33,代码来源:BookTest.php

示例12: testAddAuthor

 function testAddAuthor()
 {
     $book_name = "Yer not a wizard harry";
     $test_book = new Book($book_name);
     $test_book->save();
     $author_name = "JK Rowling";
     $test_author = new Author($author_name);
     $test_author->save();
     $test_book->addAuthor($test_author);
     $result = $test_book->getAuthors();
     $this->assertEquals($test_author, $result[0]);
 }
开发者ID:jschold,项目名称:Library,代码行数:12,代码来源:BookTest.php

示例13: Book

 function test_getAuthors()
 {
     //Arrange
     $test_book = new Book("World War Z", "Horror");
     $test_book->save();
     $test_book2 = new Book("Billy Bartle-Barnaby", "2015-07-09");
     $test_book2->save();
     $test_author = new Author("High Times", "CHEM420");
     $test_author->save();
     $test_author2 = new Author("Gavanese Jamelan", "MUSC69");
     $test_author2->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $test_book2->addAuthor($test_author2);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author, $test_author2]);
 }
开发者ID:kellimargaret,项目名称:Library-Search,代码行数:18,代码来源:BookTest.php

示例14: testGetAuthors

 function testGetAuthors()
 {
     $title = "Carrie";
     $test_book = new Book($title);
     $test_book->save();
     $name = "Stephen King";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Joe Hill";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     $this->assertEquals([$test_author2, $test_author], $test_book->getAuthors());
 }
开发者ID:umamiMike,项目名称:library-1,代码行数:15,代码来源:BookTest.php

示例15: Author

 function test_getAuthors()
 {
     //Arrange
     $name = "Giacomo Bordello";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Dude Guy";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $title = "Clarinet Seduction";
     $genre = "Romance";
     $test_book = new Book($title, $genre);
     $test_book->save();
     //Act
     $test_book->addAuthor($test_author);
     $test_book->addAuthor($test_author2);
     //Assert
     $this->assertEquals($test_book->getAuthors(), [$test_author, $test_author2]);
 }
开发者ID:r-hills,项目名称:library-1,代码行数:19,代码来源:BookTest.php


注:本文中的Book::addAuthor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。