当前位置: 首页>>代码示例>>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;未经允许,请勿转载。