當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Facade::convertToBeans方法代碼示例

本文整理匯總了PHP中RedBeanPHP\Facade::convertToBeans方法的典型用法代碼示例。如果您正苦於以下問題:PHP Facade::convertToBeans方法的具體用法?PHP Facade::convertToBeans怎麽用?PHP Facade::convertToBeans使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在RedBeanPHP\Facade的用法示例。


在下文中一共展示了Facade::convertToBeans方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testImportMeta

    /**
     * Tests whether we can send results of a query to meta data
     * when converting to bean.
     */
    public function testImportMeta()
    {
        R::nuke();
        $book = R::dispense(array('_type' => 'book', 'title' => 'Bean Recipes', 'author' => 'Meastro de la Bean'));
        $pages = R::dispenseAll('page*2');
        $book->ownPageList = reset($pages);
        R::store($book);
        $data = R::getRow('SELECT book.*,
								  COUNT(page.id) AS meta_count,
								  1234 AS meta_extra
						   FROM book
						   LEFT JOIN page ON page.book_id = book.id
						   GROUP BY book.id
						   ');
        $bean = R::convertToBean('book', $data, 'meta_');
        asrt(isset($bean->title), TRUE);
        asrt(isset($bean->author), TRUE);
        asrt(isset($bean->meta_count), FALSE);
        asrt(isset($bean->meta_extra), FALSE);
        $data = $bean->getMeta('data.bundle');
        asrt(intval($data['meta_count']), 2);
        asrt(intval($data['meta_extra']), 1234);
        //now with multiple beans
        $book = R::dispense(array('_type' => 'book', 'title' => 'Bean Adventures', 'author' => 'Mr Adventure'));
        $pages = R::dispenseAll('page*3');
        $book->ownPageList = reset($pages);
        R::store($book);
        $data = R::getAll('SELECT book.*,
								  COUNT(page.id) AS meta_pages
						   FROM book
						   LEFT JOIN page ON page.book_id = book.id
						   GROUP BY book.id
						   ');
        $books = R::convertToBeans('book', $data, 'meta_');
        $found = 0;
        foreach ($books as $book) {
            if ($book->title == 'Bean Recipes') {
                $found++;
                asrt(isset($book->title), TRUE);
                asrt(isset($book->author), TRUE);
                asrt(isset($book->meta_count), FALSE);
                asrt(isset($book->meta_extra), FALSE);
                $data = $book->getMeta('data.bundle');
                asrt(intval($data['meta_pages']), 2);
            }
            if ($book->title == 'Bean Adventures') {
                $found++;
                asrt(isset($book->title), TRUE);
                asrt(isset($book->author), TRUE);
                asrt(isset($book->meta_pages), FALSE);
                asrt(isset($book->meta_extra), FALSE);
                $data = $book->getMeta('data.bundle');
                asrt(intval($data['meta_pages']), 3);
            }
        }
        asrt($found, 2);
    }
開發者ID:gabordemooij,項目名稱:redbean,代碼行數:61,代碼來源:Bean.php

示例2: testConv2Beans

 public function testConv2Beans()
 {
     $row1 = array('id' => 1, 'title' => 'test');
     $row2 = array('id' => 2, 'title' => 'test2');
     $beans = R::convertToBeans('page', array($row1, $row2));
     asrt(count($beans), 2);
     asrt($beans[2]->title, 'test2');
 }
開發者ID:skullyframework,項目名稱:skully,代碼行數:8,代碼來源:Misc.php


注:本文中的RedBeanPHP\Facade::convertToBeans方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。