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


PHP Author::addBook方法代码示例

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


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

示例1: testSerializeObjectWithCollections

 public function testSerializeObjectWithCollections()
 {
     $book1 = new Book();
     $book1->setTitle('Foo5');
     $book1->setISBN('1234');
     $book2 = new Book();
     $book2->setTitle('Foo6');
     $book2->setISBN('1234');
     $author = new Author();
     $author->setFirstName('JAne');
     $author->addBook($book1);
     $author->addBook($book2);
     $author->save();
     $a = clone $author;
     $sa = serialize($a);
     $author->clearAllReferences();
     $this->assertEquals($author, unserialize($sa));
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:18,代码来源:BaseObjectSerializeTest.php

示例2: setUp

 public function setUp()
 {
     parent::setUp();
     $a = new Author();
     $a->setFirstName("Douglas");
     $a->setLastName("Adams");
     $b1 = new Book();
     $b1->setTitle("The Hitchhikers Guide To The Galaxy");
     $a->addBook($b1);
     $b2 = new Book();
     $b2->setTitle("The Restaurant At The End Of The Universe");
     $a->addBook($b2);
     $a->save();
     $this->author = $a;
     $this->books = array($b1, $b2);
     Propel::enableInstancePooling();
     // Clear author instance pool so the object would be fetched from the database
     AuthorPeer::clearInstancePool();
 }
开发者ID:kcornejo,项目名称:estadistica,代码行数:19,代码来源:PoisonedCacheBugTest.php

示例3: testAddBook

 function testAddBook()
 {
     //Arrange
     $name = "Ben";
     $test_author = new Author($name);
     $test_author->save();
     $book_name = "Intro to Art";
     $test_book = new Book($book_name);
     $test_book->save();
     //Act
     $test_author->addBook($test_book);
     //Assert
     $this->assertEquals($test_author->getBooks(), [$test_book]);
 }
开发者ID:kevintokheim,项目名称:Library,代码行数:14,代码来源:AuthorTest.php

示例4: testSavedObjectCreatesDifferentHashForIdenticalObjects

 /**
  * Primary key should differ
  */
 public function testSavedObjectCreatesDifferentHashForIdenticalObjects()
 {
     $book1 = new Book();
     $book1->setTitle('Foo5');
     $book1->setISBN('1234');
     $author1 = new Author();
     $author1->setFirstName('JAne');
     $author1->setLastName('JAne');
     $author1->addBook($book1);
     $author1->save();
     $author2 = new Author();
     $author2->setFirstName('JAne');
     $author2->setLastName('JAne');
     $author2->addBook($book1);
     $author2->save();
     $this->assertNotEquals($author1->hashCode(), $author2->hashCode());
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:20,代码来源:BaseObjectHashCodeTest.php

示例5: Book

 function test_findByAuthorName()
 {
     //Arrange
     $title = "Adventures on Mars";
     $test_book = new Book($title);
     $test_book->save();
     $name = "David Foster Wallace";
     $test_author = new Author($name);
     $test_author->save();
     $test_author->addBook($test_book);
     //Act
     $result = Author::findByAuthorName("David Foster Wallace");
     //Assert
     $this->assertEquals($test_author->getId(), $result);
 }
开发者ID:kevintokheim,项目名称:Liberry,代码行数:15,代码来源:AuthorTest.php

示例6: testGetBooks

 function testGetBooks()
 {
     //Arrange
     $id = null;
     $name = "Lemony Snicket";
     $test_author = new Author($id, $name);
     $test_author->save();
     $name2 = "Fresh Off The Boat";
     $test_book = new Book($id, $name2);
     $test_book->save();
     $test_author->addBook($test_book);
     $name3 = "A Series of Unfortunate Events";
     $test_book2 = new Book($id, $name3);
     $test_book2->save();
     $test_author->addBook($test_book2);
     //Act
     $result = $test_author->getBooks();
     //Assert
     $this->assertEquals([$test_book, $test_book2], $result);
 }
开发者ID:kellimargaret,项目名称:2015.08.26.Library,代码行数:20,代码来源:AuthorTest.php

示例7: testModifiedObjectOverwrite

 /**
  * This tests to see whether modified objects are being silently overwritten by calls to fk accessor methods.
  * @link       http://propel.phpdb.org/trac/ticket/509#comment:5
  */
 public function testModifiedObjectOverwrite()
 {
     BookstoreDataPopulator::populate();
     $author = new Author();
     $author->setFirstName("John");
     $author->setLastName("Public");
     $books = $author->getBooks();
     // empty, of course
     $this->assertEquals(0, count($books), "Expected empty collection.");
     $book = new Book();
     $book->setTitle("A sample book");
     $book->setISBN("INITIAL ISBN");
     $author->addBook($book);
     $author->save();
     $book->setISBN("MODIFIED ISBN");
     $books = $author->getBooks();
     $this->assertEquals(1, count($books), "Expected 1 book.");
     $this->assertSame($book, $books[0], "Expected the same object to be returned by fk accessor.");
     $this->assertEquals("MODIFIED ISBN", $books[0]->getISBN(), "Expected the modified value NOT to have been overwritten.");
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:24,代码来源:GeneratedObjectRelTest.php

示例8: testGetBooks

 function testGetBooks()
 {
     $name = "Stephen King";
     $test_author = new Author($name);
     $test_author->save();
     $title = "Carrie";
     $test_book = new Book($title);
     $test_book->save();
     $test_author->addBook($test_book);
     $title2 = "Misery";
     $test_book2 = new Book($title2);
     $test_book2->save();
     $test_author->addBook($test_book2);
     $this->assertEquals([$test_book, $test_book2], $test_author->getBooks());
 }
开发者ID:umamiMike,项目名称:Library,代码行数:15,代码来源:AuthorTest.php

示例9: Author

 function test_getBooks()
 {
     //Arrange
     $name = "Pladoh";
     $test_author = new Author($name);
     $test_author->save();
     $title = "Theory of Everything and Nothing at All";
     $genre = "Nonsense";
     $test_book = new Book($title, $genre);
     $test_book->save();
     $title2 = "Philosoraptor: A Memoir";
     $genre2 = "Alternate History/Dinosaurs";
     $test_book2 = new Book($title, $genre);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     //Assert
     $this->assertEquals($test_author->getBooks(), [$test_book, $test_book2]);
 }
开发者ID:r-hills,项目名称:library-1,代码行数:20,代码来源:AuthorTest.php

示例10: testDelete

 function testDelete()
 {
     //Arrange
     $title = "Harry Potter";
     $id = 1;
     $test_book = new Book($title, $id);
     $test_book->save();
     $name = "JK Rowling";
     $id = 1;
     $test_author = new Author($name, $id);
     $test_author->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->delete();
     //Assert
     $this->assertEquals([], $test_book->getAuthors());
 }
开发者ID:bborealis,项目名称:library,代码行数:17,代码来源:AuthorTest.php

示例11: Author

 function test_addBook_getBooks()
 {
     $name = "Jerry Garcia";
     $test_author = new Author($name);
     $test_author->save();
     $name2 = "Frank Sinatra";
     $test_author2 = new Author($name2);
     $test_author2->save();
     $book_title = "Three Blind Mice";
     $test_book = new Book($book_title);
     $test_book->save();
     $test_author->addBook($test_book);
     $result = $test_author->getBooks();
     $this->assertEquals([$test_book], $result);
 }
开发者ID:nathanhwyoung,项目名称:Library-2,代码行数:15,代码来源:AuthorTest.php

示例12: setAuthor

 /**
  * Declares an association between this object and a Author object.
  *
  * @param      Author $v
  * @return     Book The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setAuthor(Author $v = null)
 {
     if ($v === null) {
         $this->setAuthorId(NULL);
     } else {
         $this->setAuthorId($v->getId());
     }
     $this->aAuthor = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Author object, it will not be re-added.
     if ($v !== null) {
         $v->addBook($this);
     }
     return $this;
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:22,代码来源:BaseBook.php

示例13: testGetBook

 function testGetBook()
 {
     //Arrange
     $first_name = "John";
     $last_name = "Steinbeck";
     $test_author = new Author($first_name, $last_name);
     $test_author->save();
     $title = "Grapes of Wrath";
     $test_book = new Book($title);
     $test_book->save();
     $title2 = "Cannery Row";
     $test_book2 = new Book($title2);
     $test_book2->save();
     //Act
     $test_author->addBook($test_book);
     $test_author->addBook($test_book2);
     $result = $test_author->getBook();
     //Assert
     $this->assertEquals([$test_book, $test_book2], $result);
 }
开发者ID:jtorrespdx,项目名称:library,代码行数:20,代码来源:AuthorTest.php

示例14: PDO

require_once __DIR__ . "/../src/Author.php";
require_once __DIR__ . "/../src/Book.php";
$app = new Silex\Application();
$app['debug'] = true;
$server = 'mysql:host=localhost;dbname=library';
$username = 'root';
$password = 'root';
$DB = new PDO($server, $username, $password);
use Symfony\Component\HttpFoundation\Request;
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', array('authors' => Author::getAll(), 'books' => Book::getAll()));
});
$app->post("/author_book", function () use($app) {
    $title = $_POST['title'];
    $book = new Book($title, $id = null);
    $book->save();
    $name = $_POST['name'];
    $author = new Author($name, $id = null);
    $author->save();
    $result = $author->addBook($book);
    return $app['twig']->render('index.html.twig', array('books' => Book::getAll(), 'authors' => Author::getAll()));
});
$app->post("/delete_all", function () use($app) {
    $GLOBALS['DB']->exec("DELETE FROM authors_books_t;");
    Author::deleteAll();
    Book::deleteAll();
    return $app['twig']->render('index.html.twig', array('authors' => Author::getAll(), 'books' => Book::getAll()));
});
return $app;
开发者ID:CaseyH33,项目名称:Library,代码行数:31,代码来源:app.php

示例15: setAuthor

 /**
  * Declares an association between this object and a Author object.
  * Mapped by fields authorId
  * 
  * @param Author $author
  * @return $this|\Book The current object (for fluent API support)
  */
 public function setAuthor(Author $author = null)
 {
     $this->author = $author;
     // Setup bidirectional relationship.
     if (null !== $author) {
         $author->addBook($this);
     }
 }
开发者ID:dracony,项目名称:forked-php-orm-benchmark,代码行数:15,代码来源:Book.php


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