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


PHP Book::toArray方法代码示例

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


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

示例1: testToArrayDeep

 public function testToArrayDeep()
 {
     $author = new Author();
     $author->setId(5678);
     $author->setFirstName('George');
     $author->setLastName('Byron');
     $book = new Book();
     $book->setId(9012);
     $book->setTitle('Don Juan');
     $book->setISBN('0140422161');
     $book->setPrice(12.99);
     $book->setAuthor($author);
     $coll = new ArrayCollection();
     $coll->setModel('Propel\\Tests\\Bookstore\\Book');
     $coll[] = $book->toArray(TableMap::TYPE_PHPNAME, true, array(), true);
     $expected = array(array('Id' => 9012, 'Title' => 'Don Juan', 'ISBN' => '0140422161', 'Price' => 12.99, 'PublisherId' => null, 'AuthorId' => 5678, 'Author' => array('Id' => 5678, 'FirstName' => 'George', 'LastName' => 'Byron', 'Email' => null, 'Age' => null, 'Books' => array('Book_0' => '*RECURSION*'))));
     $this->assertEquals($expected, $coll->toArray());
 }
开发者ID:badelas,项目名称:thelia,代码行数:18,代码来源:ArrayCollectionTest.php

示例2: testToArray

 /**
  * Tests the Base[Object]::toArray() method
  */
 public function testToArray()
 {
     $types = array(BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME, BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM);
     $book = new Book();
     $book->fromArray(array('Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X'));
     $expecteds = array(BasePeer::TYPE_PHPNAME => array('Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X'), BasePeer::TYPE_STUDLYPHPNAME => array('title' => 'Harry Potter and the Order of the Phoenix', 'iSBN' => '043935806X'), BasePeer::TYPE_COLNAME => array('book.TITLE' => 'Harry Potter and the Order of the Phoenix', 'book.ISBN' => '043935806X'), BasePeer::TYPE_FIELDNAME => array('title' => 'Harry Potter and the Order of the Phoenix', 'isbn' => '043935806X'), BasePeer::TYPE_NUM => array('1' => 'Harry Potter and the Order of the Phoenix', '2' => '043935806X'));
     foreach ($types as $type) {
         $expected = $expecteds[$type];
         $result = $book->toArray($type);
         // remove ID since its autoincremented at each test iteration
         $result = array_slice($result, 1, 2, true);
         $this->assertEquals($expected, $result, 'expected was: ' . print_r($expected, 1) . 'but toArray() returned ' . print_r($result, 1));
     }
 }
开发者ID:norfil,项目名称:Propel2,代码行数:17,代码来源:FieldnameRelatedTest.php

示例3: testToArrayKeyType

 public function testToArrayKeyType()
 {
     $b = new Book();
     $b->setTitle('Don Juan');
     $arr1 = $b->toArray(TableMap::TYPE_COLNAME);
     $expectedKeys = array(BookTableMap::ID, BookTableMap::TITLE, BookTableMap::ISBN, BookTableMap::PRICE, BookTableMap::PUBLISHER_ID, BookTableMap::AUTHOR_ID);
     $this->assertEquals($expectedKeys, array_keys($arr1), 'toArray() accepts a $keyType parameter to change the result keys');
     $this->assertEquals('Don Juan', $arr1[BookTableMap::TITLE], 'toArray() returns an associative array representation of the object');
 }
开发者ID:robin850,项目名称:Propel2,代码行数:9,代码来源:GeneratedObjectTest.php

示例4: testToArrayWithForeignObjects

 public function testToArrayWithForeignObjects()
 {
     $types = [TableMap::TYPE_PHPNAME, TableMap::TYPE_CAMELNAME, TableMap::TYPE_COLNAME, TableMap::TYPE_FIELDNAME, TableMap::TYPE_NUM];
     $review = new Review();
     $review->setRecommended(true)->setReviewedBy('Someone')->setReviewDate(null);
     $book = new Book();
     $book->setTitle('Harry Potter and the Order of the Phoenix')->setISBN('043935806X')->addReview($review)->setPrice(10);
     $expecteds = array(TableMap::TYPE_PHPNAME => ['Id' => null, 'Title' => 'Harry Potter and the Order of the Phoenix', 'ISBN' => '043935806X', 'Price' => 10.0, 'PublisherId' => null, 'AuthorId' => null, 'Reviews' => [['Id' => null, 'ReviewedBy' => 'Someone', 'ReviewDate' => null, 'Recommended' => true, 'Status' => null, 'BookId' => null, 'Book' => '*RECURSION*']]], TableMap::TYPE_CAMELNAME => array('id' => null, 'title' => 'Harry Potter and the Order of the Phoenix', 'iSBN' => '043935806X', 'price' => 10.0, 'publisherId' => null, 'authorId' => null, 'reviews' => [['id' => null, 'reviewedBy' => 'Someone', 'reviewDate' => null, 'recommended' => true, 'status' => null, 'bookId' => null, 'book' => '*RECURSION*']]), TableMap::TYPE_COLNAME => array('book.ID' => null, 'book.TITLE' => 'Harry Potter and the Order of the Phoenix', 'book.ISBN' => '043935806X', 'book.PRICE' => 10.0, 'book.PUBLISHER_ID' => null, 'book.AUTHOR_ID' => null, 'Reviews' => [['review.ID' => null, 'review.REVIEWED_BY' => 'Someone', 'review.REVIEW_DATE' => null, 'review.RECOMMENDED' => true, 'review.STATUS' => null, 'review.BOOK_ID' => null, 'Book' => '*RECURSION*']]), TableMap::TYPE_FIELDNAME => array('id' => null, 'title' => 'Harry Potter and the Order of the Phoenix', 'isbn' => '043935806X', 'price' => 10.0, 'publisher_id' => null, 'author_id' => null, 'reviews' => [['id' => null, 'reviewed_by' => 'Someone', 'review_date' => null, 'recommended' => true, 'status' => null, 'book_id' => null, 'book' => '*RECURSION*']]), TableMap::TYPE_NUM => array('0' => null, '1' => 'Harry Potter and the Order of the Phoenix', '2' => '043935806X', '3' => 10.0, '4' => null, '5' => null, 'Reviews' => [['0' => null, '1' => 'Someone', '2' => null, '3' => 1, '4' => null, '5' => null, 'Book' => '*RECURSION*']]));
     foreach ($types as $type) {
         $expected = $expecteds[$type];
         $result = $book->toArray($type, true, [], true);
         $this->assertEquals($expected, $result, 'expected was: ' . print_r($expected, 1) . 'but toArray() returned ' . print_r($result, 1));
     }
 }
开发者ID:bondarovich,项目名称:Propel2,代码行数:14,代码来源:FieldnameRelatedTest.php


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