本文整理汇总了PHP中RedBeanPHP\Facade::exportAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Facade::exportAll方法的具体用法?PHP Facade::exportAll怎么用?PHP Facade::exportAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\Facade
的用法示例。
在下文中一共展示了Facade::exportAll方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
public function index(Request $request)
{
$beans = R::findAll($model);
$records = R::exportAll($beans, true);
$tables = R::getAll('SELECT name FROM sqlite_master WHERE type = "table"');
return view('umodel.index', ['records' => $records, 'tables' => $tables]);
}
示例2: testAutoResolver
/**
* Tests automatic resolvement of parent beans
* without fetchAs() using inferFetchType (foreign keys).
*
* @return void
*/
public function testAutoResolver()
{
R::nuke();
list($project, $teacher, $student) = R::dispenseAll('project,person,person');
$teacher->name = 'teacher';
$student->name = 'student';
$project->teacher = $teacher;
$project->student = $student;
R::store($project);
$project = $project->fresh();
asrt($project->teacher instanceof OODBBean, TRUE);
asrt($project->student instanceof OODBBean, TRUE);
asrt($project->teacher->name, 'teacher');
asrt($project->student->name, 'student');
$project2 = R::dispense('project');
$teacher2 = R::dispense('person');
$teacher2->name = 'teacher2';
$project2->teacher = $teacher2;
R::store($project2);
$project2 = $project2->fresh();
asrt($project2->teacher instanceof OODBBean, TRUE);
asrt($project2->teacher->name, 'teacher2');
asrt(is_null($project2->student), TRUE);
$project = $project->fresh();
asrt($project->fetchAs('person')->teacher instanceof OODBBean, TRUE);
asrt($project->fetchAs('person')->student instanceof OODBBean, TRUE);
asrt($project->fetchAs('person')->teacher->name, 'teacher');
asrt($project->fetchAs('person')->student->name, 'student');
$project = $project->fresh();
$export = R::exportAll(array($project), TRUE);
asrt(isset($export[0]['teacher']['name']), TRUE);
asrt(isset($export[0]['student']['name']), TRUE);
asrt($export[0]['teacher']['name'], 'teacher');
asrt($export[0]['student']['name'], 'student');
//Also test the default implementation...
$nullWriter = new \NullWriter(R::getDatabaseAdapter());
asrt(is_null($nullWriter->inferFetchType('test', 'test')), TRUE);
//Realteacher should take precedence over fetchAs-teacher, name conventions first!
//also: ensure we do not use autoresolv for anything except when truly necessary! (performance)
$realTeacher = R::dispense('teacher');
$realTeacher->name = 'real';
R::store($realTeacher);
//ID must be same
asrt($realTeacher->id, $teacher->id);
$project = $project->fresh();
asrt($project->teacher->name, 'real');
}
示例3: testExportIssue
/**
* In the past it was not possible to export beans
* like 'feed' (Model_Feed).
*
* @return void
*/
public function testExportIssue()
{
R::nuke();
$feed = R::dispense('feed');
$feed->post = array('first', 'second');
R::store($feed);
$rows = R::getAll('SELECT * FROM feed');
asrt($rows[0]['post'], '["first","second"]');
$feed = $feed->fresh();
asrt(is_array($feed->post), TRUE);
asrt($feed->post[0], 'first');
asrt($feed->post[1], 'second');
R::store($feed);
$rows = R::getAll('SELECT * FROM feed');
asrt($rows[0]['post'], '["first","second"]');
$feed = R::load('feed', $feed->id);
$feed->post[] = 'third';
R::store($feed);
$rows = R::getAll('SELECT * FROM feed');
asrt($rows[0]['post'], '["first","second","third"]');
$feed = $feed->fresh();
asrt(is_array($feed->post), TRUE);
asrt($feed->post[0], 'first');
asrt($feed->post[1], 'second');
asrt($feed->post[2], 'third');
//now the catch: can we use export?
//PHP Fatal error: Call to a member function export() on a non-object
$feeds = R::exportAll(R::find('feed'));
asrt(is_array($feeds), TRUE);
$feed = reset($feeds);
asrt($feed['post'][0], 'first');
asrt($feed['post'][1], 'second');
asrt($feed['post'][2], 'third');
//can we also dup()?
$feedOne = R::findOne('feed');
R::store(R::dup($feedOne));
asrt(R::count('feed'), 2);
//can we delete?
R::trash($feedOne);
asrt(R::count('feed'), 1);
$feedTwo = R::findOne('feed');
$feed = $feedTwo->export();
asrt($feed['post'][0], 'first');
asrt($feed['post'][1], 'second');
asrt($feed['post'][2], 'third');
}
示例4: testCopyRecursion
/**
* Test whether recursion happens
*/
public function testCopyRecursion()
{
$document = R::dispense('document');
$id = R::store($document);
$document->ownDocument[] = $document;
R::store($document);
$duplicate = R::dup($document);
pass();
//if RB cant handle this is will crash (nesting level error from PHP).
$id2 = R::store($duplicate);
$duplicate = R::load('document', $id);
asrt((int) $document->document_id, $id);
asrt((int) $duplicate->document_id, $id2);
// Export variant
$duplicate = R::exportAll($document);
asrt((int) $duplicate[0]['document_id'], $id);
}
示例5: testBasicOperationsFrozen
/**
* Test basic operations in frozen mode.
*/
public function testBasicOperationsFrozen()
{
R::nuke();
$author = R::xdispense(AUTHOR);
$author->name = 'Mr. Quill';
$book = R::xdispense(BOOK);
$book->title = 'Good Stories';
$book2 = R::xdispense(BOOK);
$book2->title = 'Good Stories 2';
$friend = R::xdispense(FRIEND);
$friend->name = 'Muse';
$publisher = R::xdispense(PUBLISHER);
$publisher->name = 'Good Books';
$author->{BOOKLIST} = array($book, $book2);
$author->{FRIENDLIST}[] = $friend;
$author->{PUBLISHER} = $publisher;
$coAuthor = R::xdispense(AUTHOR);
$coAuthor->name = 'Xavier';
$book2->{COAUTHOR} = $coAuthor;
R::store($author);
R::freeze(TRUE);
asrt($author->name, 'Mr. Quill');
asrt(count($author->{BOOKLIST}), 2);
$firstBook = reset($author->{BOOKLIST});
asrt($firstBook->title, 'Good Stories');
asrt(count($author->{FRIENDLIST}), 1);
$firstFriend = reset($author->{FRIENDLIST});
$parent = $author->{PUBLISHER};
asrt($parent instanceof OODBBean, TRUE);
$tables = R::inspect();
//have all tables been prefixed?
foreach ($tables as $table) {
asrt(strpos($table, 'tbl_'), 0);
}
//Can we make an export?
$export = R::exportAll(R::findOne(AUTHOR), TRUE);
$export = reset($export);
asrt(isset($export[PUBLISHER]), TRUE);
asrt(isset($export[BOOKLIST]), TRUE);
asrt(isset($export[FRIENDLIST]), TRUE);
asrt(isset($export['ownBook']), FALSE);
asrt(isset($export['sharedFriend']), FALSE);
asrt(isset($export['publisher']), FALSE);
R::freeze(FALSE);
}
示例6: updatePackageCost
function updatePackageCost($id, $cost, $label)
{
$packageCost = R::load('packagecost', $id);
$packageCost->cost = $cost;
$packageCost->label = $label;
R::store($packageCost);
return json_encode(R::exportAll($packageCost));
}
示例7: testExportAll
/**
* ExportAll.
*
* @return void
*/
public function testExportAll()
{
testpack('Test exportAll');
$redbean = R::getRedBean();
$bean = new OODBBean();
$bean->import(array("a" => 1, "b" => 2));
$bean->setMeta("justametaproperty", "hellothere");
$arr = $bean->export();
asrt(is_array($arr), TRUE);
asrt(isset($arr["a"]), TRUE);
asrt(isset($arr["b"]), TRUE);
asrt($arr["a"], 1);
asrt($arr["b"], 2);
asrt(isset($arr["__info"]), FALSE);
$arr = $bean->export(TRUE);
asrt(isset($arr["__info"]), TRUE);
asrt($arr["a"], 1);
asrt($arr["b"], 2);
$exportBean = $redbean->dispense("abean");
$exportBean->setMeta("metaitem.bla", 1);
$exportedBean = $exportBean->export(TRUE);
asrt($exportedBean["__info"]["metaitem.bla"], 1);
asrt($exportedBean["__info"]["type"], "abean");
// Can we determine whether a bean is empty?
testpack('test $bean->isEmpty() function');
$bean = R::dispense('bean');
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
$bean->property = 1;
asrt($bean->isEmpty(), FALSE);
asrt(count($bean) > 0, TRUE);
$bean->property = 0;
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
$bean->property = FALSE;
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
$bean->property = NULL;
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
unset($bean->property);
asrt($bean->isEmpty(), TRUE);
asrt(count($bean) > 0, TRUE);
// Export bug I found
$bandmember = R::dispense('bandmember');
$bandmember->name = 'Duke';
$instrument = R::dispense('instrument');
$instrument->name = 'Piano';
$bandmember->ownInstrument[] = $instrument;
$a = R::exportAll($bandmember);
pass();
asrt(isset($a[0]), TRUE);
asrt((int) $a[0]['id'], 0);
asrt($a[0]['name'], 'Duke');
asrt($a[0]['ownInstrument'][0]['name'], 'Piano');
R::nuke();
$v = R::dispense('village');
$b = R::dispense('building');
$v->name = 'a';
$b->name = 'b';
$v->ownBuilding[] = $b;
$id = R::store($v);
$a = R::exportAll($v);
asrt($a[0]['name'], 'a');
asrt($a[0]['ownBuilding'][0]['name'], 'b');
$v = R::load('village', $id);
$b2 = R::dispense('building');
$b2->name = 'c';
$v->ownBuilding[] = $b2;
$a = R::exportAll($v);
asrt($a[0]['name'], 'a');
asrt($a[0]['ownBuilding'][0]['name'], 'b');
asrt(count($a[0]['ownBuilding']), 2);
list($r1, $r2) = R::dispense('army', 2);
$r1->name = '1';
$r2->name = '2';
$v->sharedArmy[] = $r2;
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 1);
R::store($v);
$v = R::load('village', $id);
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 1);
asrt($a[0]['name'], 'a');
asrt($a[0]['ownBuilding'][0]['name'], 'b');
asrt(count($a[0]['ownBuilding']), 2);
$v->sharedArmy[] = $r1;
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 2);
$v = R::load('village', $id);
$a = R::exportAll($v);
asrt(count($a[0]['sharedArmy']), 1);
$v->sharedArmy[] = $r1;
R::store($v);
$v = R::load('village', $id);
//.........这里部分代码省略.........
示例8: runOnce
/**
* Run tests
*/
private function runOnce($n = TRUE)
{
$books = R::dispense('book', 10);
$pages = R::dispense('page', 10);
$readers = R::dispense('reader', 10);
$texts = R::dispense('text', 10);
$i = 0;
foreach ($books as $book) {
$book->name = 'book-' . $i++;
}
$i = 0;
foreach ($pages as $page) {
$page->name = 'page-' . $i++;
}
$i = 0;
foreach ($readers as $reader) {
$reader->name = 'reader-' . $i++;
}
$i = 0;
foreach ($texts as $text) {
$text->content = 'lorem ipsum -' . $i++;
}
foreach ($texts as $text) {
$pages[array_rand($pages)]->ownText[] = $text;
}
foreach ($pages as $page) {
$books[array_rand($books)]->ownPage[] = $page;
}
foreach ($readers as $reader) {
$books[array_rand($books)]->sharedReader[] = $reader;
}
$i = $noOfReaders = $noOfPages = $noOfTexts = 0;
foreach ($books as $key => $book) {
$i++;
$noOfPages += count($book->ownPage);
$noOfReaders += count($book->sharedReader);
foreach ($book->ownPage as $page) {
$noOfTexts += count($page->ownText);
}
$arr = R::exportAll($book);
echo "\nIntermediate info: " . json_encode($arr) . ": Totals = {$i},{$noOfPages},{$noOfReaders},{$noOfTexts} ";
$this->compare($book, $arr[0]);
$copiedBook = R::dup($book);
$copiedBookArray = R::exportAll($copiedBook);
$this->compare($book, $copiedBookArray[0]);
$copiedBookArrayII = $copiedBook->export();
$this->compare($book, $copiedBookArrayII);
$copyFromCopy = R::dup($copiedBook);
$copyFromCopyArray = R::exportAll($copyFromCopy);
$this->compare($book, $copyFromCopyArray[0]);
$copyFromCopyArrayII = $copyFromCopy->export();
$this->compare($book, $copyFromCopyArrayII);
$id = R::store($book);
$copiedBook = R::dup($book);
R::store($book);
//should not be damaged
$copiedBookArray = R::exportAll($copiedBook);
$originalBookArray = R::exportAll($book);
$this->compare($copiedBook, $copiedBookArray[0]);
$this->compare($book, $originalBookArray[0]);
$book = R::load('book', $id);
$this->compare($book, $originalBookArray[0]);
$copiedBook = R::dup($book);
$this->compare($copiedBook, $copiedBook->export());
R::store($copiedBook);
$this->compare($copiedBook, $copiedBook->export());
$copyFromCopy = R::dup($copiedBook);
$this->compare($copyFromCopy, $copyFromCopy->export());
R::store($copyFromCopy);
$newPage = R::dispense('page');
$newPage->name = 'new';
$copyFromCopy->ownPage[] = $newPage;
$modifiedCopy = R::dup($copyFromCopy);
$exportMod = R::exportAll($modifiedCopy);
$this->compare($modifiedCopy, $exportMod[0]);
asrt(count($modifiedCopy->ownPage), count($copiedBook->ownPage) + 1);
R::store($modifiedCopy);
if ($n) {
asrt((int) R::getCell('SELECT count(*) FROM book'), $i * 4);
asrt((int) R::getCell('SELECT count(*) FROM page'), $noOfPages * 4 + $i);
asrt((int) R::getCell('SELECT count(*) FROM text'), $noOfTexts * 4);
asrt((int) R::getCell('SELECT count(*) FROM book_reader'), $noOfReaders * 4);
asrt((int) R::getCell('SELECT count(*) FROM reader'), $noOfReaders);
}
}
if ($n) {
asrt($noOfTexts, 10);
asrt($noOfReaders, 10);
asrt($noOfPages, 10);
asrt($i, 10);
}
}
示例9: array
$lines = R::exportAll(R::find('line', 'WHERE start_point_id=' . $city[0]['id']));
$timetableCityDay = array();
foreach ($lines as $line) {
$timetable = R::exportAll(R::find('timetable', 'WHERE line_id=' . $line['id'] . ' AND day=' . $day));
var_dump($timetable);
if (!empty($timetable)) {
$timetableCityDay[] = array($timetable[0]['start_time'], $line['end_point_id']);
}
}
echo json_encode($timetableCityDay);
});
//return all the cities with coordinates
$app->get('/city', function () {
$city = R::exportAll(R::find('city'));
echo json_encode($city);
});
//Return line,price,start_time and distance by name city departure and name city arrival
$app->get('/nextStart/:cityNameDeparture/:cityNameArrival', function ($cityNameDeparture, $cityNameArrival) {
$cityDeparture = R::exportAll(R::find('city', 'WHERE name="' . $cityNameDeparture . '"'));
$cityArrival = R::exportAll(R::find('city', 'WHERE name="' . $cityNameArrival . '"'));
$lines = R::exportAll(R::find('line', 'WHERE start_point_id=' . $cityDeparture[0]['id'] . ' AND end_point_id=' . $cityArrival[0]['id']));
$timetableTrip = array();
foreach ($lines as $line) {
$timetable = R::exportAll(R::find('timetable', 'WHERE line_id=' . $line['id']));
if (!empty($timetable)) {
$timetableTrip[] = array($timetable[0]['start_time'], $line['price'], $line['distance'], $line['end_point_id']);
}
}
echo json_encode($timetableTrip);
});
$app->run();
示例10: function
<?php
require 'vendor/autoload.php';
use RedBeanPHP\Facade as R;
$app = new \Slim\Slim();
$app->get('/line/:numLine', function ($numLine) {
R::setup('mysql:host=localhost;
dbname=db_goBus', 'root', 'pwsio');
$row = R::findAll('line', ' where id=' . $numLine);
//display data line entered into id 'name table', 'condition sup'
$exportRow = R::exportAll($row);
echo json_encode($exportRow);
//js_encode serve to display data all in the inpu line on url
});
$app->run();
示例11: function
<?php
//inlcude of Slim Framework and RedBeanPHP
require 'vendor/autoload.php';
/* Declare RedBeanPHP
* RedBean version : 4.2.1
*/
use RedBeanPHP\Facade as R;
//Declare Slim
$app = new \Slim\Slim();
//Connection at the database by RedBeanPHP
R::setup('mysql:host=localhost;dbname=GoBus_v3.0', 'root', 'pwsio');
//Route
$app->get('/city', function () {
$city = R::findAll('city');
echo json_encode(R::exportAll($city));
});
$app->run();