本文整理汇总了PHP中RedBeanPHP\Facade::findAll方法的典型用法代码示例。如果您正苦于以下问题:PHP Facade::findAll方法的具体用法?PHP Facade::findAll怎么用?PHP Facade::findAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBeanPHP\Facade
的用法示例。
在下文中一共展示了Facade::findAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: getSettings
public function getSettings()
{
$settings = array();
$result = RedBean::findAll('settings');
foreach ($result as $setting) {
$settings[$setting->name] = $setting->value;
}
return $settings;
}
示例3: getResults
/**
* @return array
*/
public function getResults()
{
if ($this->storedNumber > $this->maxResults) {
$startFrom = $this->maxResults * $this->startPage;
$extraSQL = 'ORDER BY id ASC LIMIT ' . $startFrom . ',' . $this->maxResults;
return Facade::findAll($this->DBTable, $extraSQL);
} else {
return Facade::findAll($this->DBTable);
}
}
示例4: testLargeNum
/**
* Test for issue #386.
* Can we use large numbers in LIMIT ?
*
* @return void
*/
public function testLargeNum()
{
$number = R::dispense('number');
$number->name = 'big number';
R::store($number);
//This should not cause an error... (some people use LIMIT 0, HUGE to simulate OFFSET on MYSQL).
$beans = R::findAll('number', ' LIMIT ? ', array(PHP_INT_MAX));
asrt(is_array($beans), TRUE);
asrt(count($beans), 1);
pass();
}
示例5: listData
protected function listData()
{
$instances = R::findAll($this->model());
$instanceList = array();
if (!empty($instances)) {
foreach ($instances as $instance) {
$actions = array('data' => '<a title="View" href="' . $this->app->getRouter()->getUrl('admin/admins/edit', array('id' => $instance->id)) . '" data-toggle="dialog"><span class="icon-pencil"></span></a>
<a title="Delete" href="' . $this->app->getRouter()->getUrl('admin/admins/delete', array('id' => $instance->id)) . '" data-toggle="dialog"><span class="icon-trash"></span></a>', 'class' => 'TAC');
$instanceList[] = array($instance->email, $instance->name, $instance->status, TimeHelper::date($this->app->config('adminLongDateTimeFormat'), $instance->created_at), $actions);
}
}
return $instanceList;
}
示例6: testLargeNum
/**
* Test for issue #386.
* Can we use large numbers in LIMIT ?
*
* @return void
*/
public function testLargeNum()
{
if (defined('HHVM_VERSION')) {
return;
}
//oops hhvm has incorrect binding for large nums.
$number = R::dispense('number');
$number->name = 'big number';
R::store($number);
//This should not cause an error... (some people use LIMIT 0, HUGE to simulate OFFSET on MYSQL).
$beans = R::findAll('number', ' LIMIT ? ', array(PHP_INT_MAX));
asrt(is_array($beans), TRUE);
asrt(count($beans), 1);
pass();
}
示例7: mergeSettingsToConfig
/**
* Merge settings to config.
*/
protected function mergeSettingsToConfig()
{
try {
$dbConfig = $this->getConfigObject()->getProtected('dbConfig');
if (!empty($dbConfig)) {
$settings = R::findAll('setting');
if (!empty($settings)) {
foreach ($settings as $setting) {
$value = $setting->value;
settype($value, $setting->type);
if ($setting->is_client) {
$this->config->setPublic($setting->name, $value);
} else {
$this->config->setProtected($setting->name, $value);
}
}
}
}
} catch (\Exception $e) {
}
}
示例8: testValidatesUniqueness
public function testValidatesUniqueness()
{
R::freeze(false);
$foo1 = $this->app->createModel('foo', array('name' => 'a', 'exists_create' => 'b', 'exists_update' => 'c', 'unique' => 'unique', 'unique_create' => 'unique_create', 'unique_update' => 'unique_update'));
R::store($foo1);
$this->assertNotEmpty($foo1->getID());
$rows = R::findAll('foo', "`unique` = ?", array('unique'));
$this->assertEquals(1, count($rows));
$foo = $this->app->createModel('foo', array('name' => 'a', 'exists_create' => 'b', 'exists_update' => 'c', 'unique' => 'unique', 'unique_create' => 'unique_create', 'unique_update' => 'unique_update'));
try {
R::store($foo);
} catch (\Exception $e) {
$this->assertNotEmpty($foo->getErrors('unique'));
$this->assertNotEmpty($foo->getErrors('unique_create'));
$this->assertEmpty($foo->getErrors('unique_update'));
}
$foo->import(array('unique' => 'unique1', 'unique_create' => 'unique_create1'));
R::store($foo);
$this->assertNotEmpty($foo->getID());
$this->assertEmpty($foo->getErrors('unique'));
$this->assertEmpty($foo->getErrors('unique_create'));
$this->assertEmpty($foo->getErrors('unique_update'));
// Must change an attribute otherwise RedBean does not want to update.
$foo->set('unique_create', 'unique_create');
try {
R::store($foo);
} catch (\Exception $e) {
$this->assertEmpty($foo->getErrors('unique'));
$this->assertEmpty($foo->getErrors('unique_create'));
$this->assertNotEmpty($foo->getErrors('unique_update'));
}
$foo->set('unique_update', 'unique_update1');
R::store($foo);
$this->assertEmpty($foo->getErrors('unique'));
$this->assertEmpty($foo->getErrors('unique_create'));
$this->assertEmpty($foo->getErrors('unique_update'));
R::freeze($this->frozen);
}
示例9: listData
/**
* Data used in index listing.
* @return array
*/
protected function listData()
{
$sql = "is_visible = ? ORDER BY position";
/** @var \RedBean_SimpleModel[] $instanceBeans */
$instanceBeans = R::findAll('setting', $sql, array(true));
$instanceRows = array();
if (!empty($instanceBeans)) {
$this->app->getTemplateEngine()->loadPlugin('smarty_modifier_truncate', true);
foreach ($instanceBeans as $instanceBean) {
/** @var \TestApp\Models\Setting $instance */
$instance = $instanceBean->box();
$actions = array('data' => '<a title="View" href="' . $this->app->getRouter()->getUrl('admin/settings/edit', array('id' => $instance->get('id'))) . '" data-toggle="dialog"><span class="icon-pencil"></span></a>', 'class' => 'TAC');
if ($instance->get('input_type') == 'password') {
$value = '********';
} else {
$value = smarty_modifier_truncate($instance->getDisplayValue(), 40, '...', true);
}
$instanceRow = array($instance->get('name'), $value, $actions, $instance->get('position'));
$instanceRows[] = $instanceRow;
}
}
return $instanceRows;
}
示例10: delete
/**
* @param int $qid
*
* @return void
*/
public function delete($qid)
{
Facade::trash('questions', $qid);
$answersToDelete = Facade::findAll('answers', 'qid = :qid', [':qid' => $qid]);
Facade::trashAll($answersToDelete);
}
示例11: testCommonUsageFacade
/**
* Test common Facade usage scenarios.
*
* @return void
*/
public function testCommonUsageFacade()
{
$toolbox = R::getToolBox();
$adapter = $toolbox->getDatabaseAdapter();
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
$a = new AssociationManager($toolbox);
asrt(R::getRedBean() instanceof OODB, TRUE);
asrt(R::getToolBox() instanceof ToolBox, TRUE);
asrt(R::getDatabaseAdapter() instanceof Adapter, TRUE);
asrt(R::getWriter() instanceof QueryWriter, TRUE);
$book = R::dispense("book");
asrt($book instanceof OODBBean, TRUE);
$book->title = "a nice book";
$id = R::store($book);
asrt($id > 0, TRUE);
$book = R::load("book", (int) $id);
asrt($book->title, "a nice book");
asrt(R::load('book', 999)->title, NULL);
R::freeze(TRUE);
try {
R::load('bookies', 999);
fail();
} catch (\Exception $e) {
pass();
}
R::freeze(FALSE);
$author = R::dispense("author");
$author->name = "me";
R::store($author);
$book9 = R::dispense("book");
$author9 = R::dispense("author");
$author9->name = "mr Nine";
$a9 = R::store($author9);
$book9->author_id = $a9;
$bk9 = R::store($book9);
$book9 = R::load("book", $bk9);
$author = R::load("author", $book9->author_id);
asrt($author->name, "mr Nine");
R::trash($author);
R::trash($book9);
pass();
$book2 = R::dispense("book");
$book2->title = "second";
R::store($book2);
$book3 = R::dispense("book");
$book3->title = "third";
R::store($book3);
asrt(count(R::find("book")), 3);
asrt(count(R::findAll("book")), 3);
asrt(count(R::findAll("book", " LIMIT 2")), 2);
asrt(count(R::find("book", " id=id ")), 3);
asrt(count(R::find("book", " title LIKE ?", array("third"))), 1);
asrt(count(R::find("book", " title LIKE ?", array("%d%"))), 2);
// Find without where clause
asrt(count(R::findAll('book', ' order by id')), 3);
R::trash($book3);
R::trash($book2);
asrt(count(R::getAll("SELECT * FROM book ")), 1);
asrt(count(R::getCol("SELECT title FROM book ")), 1);
asrt((int) R::getCell("SELECT 123 "), 123);
$book = R::dispense("book");
$book->title = "not so original title";
$author = R::dispense("author");
$author->name = "Bobby";
R::store($book);
$aid = R::store($author);
$author = R::findOne("author", " name = ? ", array("Bobby"));
}
示例12: validates
/**
* This method won't get called when R::store() called when no change to instance is made.
*/
public function validates()
{
$this->errors = array();
if (!$this->getID()) {
$this->validatesOnCreate();
} else {
$this->validatesOnUpdate();
}
$this->validatesOnSave();
$mustExists = $this->validatesExistenceOf();
if (!$this->getID()) {
$mustExists = array_merge($mustExists, $this->validatesExistenceOnCreateOf());
} else {
$mustExists = array_merge($mustExists, $this->validatesExistenceOnUpdateOf());
}
if (!empty($mustExists)) {
foreach ($mustExists as $var) {
$value = $this->{$var};
// PHP Gotcha: somehow empty($this->$var) does not work, maybe because $var is a (magic) function.
if (empty($value)) {
$varStr = str_replace('_', ' ', $var);
$varStr = preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]/', ' $0', $varStr);
$varStr = ucfirst(strtolower($varStr));
$this->addError($this->app->getTranslator()->translate('mustExists', array('varStr' => $varStr)), $var);
}
}
}
$mustUnique = $this->validatesUniquenessOf();
if (!$this->getID()) {
$mustUnique = array_merge($mustUnique, $this->validatesUniquenessOnCreateOf());
} else {
$mustUnique = array_merge($mustUnique, $this->validatesUniquenessOnUpdateOf());
}
if (!empty($mustUnique)) {
foreach ($mustUnique as $var) {
$rows = R::findAll($this->getTableName(), "`{$var}` = ?", array($this->get($var)));
$count = count($rows);
$varStr = str_replace('_', ' ', $var);
$varStr = preg_replace('/(?!^)[A-Z]{2,}(?=[A-Z][a-z])|[A-Z][a-z]/', ' $0', $varStr);
$varStr = ucfirst(strtolower($varStr));
if ($count > 0) {
$id = $this->getID() ? $this->getID() : 0;
foreach ($rows as $row) {
if ($row->getID() != $id) {
$this->addError($this->app->getTranslator()->translate('mustUnique', array('varStr' => $varStr)), $var);
break;
}
}
}
}
}
return !$this->hasError();
}
示例13: testFullSupport
//.........这里部分代码省略.........
}
asrt(!is_null($blueRoom), TRUE);
asrt(is_array($blueRoom->sharedGhostList), TRUE);
asrt(count($blueRoom->sharedGhostList), 3);
$names = array();
foreach ($blueRoom->sharedGhost as $ghost) {
$names[] = $ghost->name;
}
sort($names);
$names = implode(',', $names);
asrt($names, 'one,three,two');
$rooms = $haunted->xownRoomList;
$redRoom = NULL;
foreach ($rooms as $room) {
if ($room->name === 'Red Room') {
$redRoom = $room;
break;
}
}
$names = array();
foreach ($redRoom->sharedGhost as $ghost) {
$names[] = $ghost->name;
}
sort($names);
$names = implode(',', $names);
asrt($names, 'two,zero');
asrt(!is_null($redRoom), TRUE);
asrt(is_array($redRoom->sharedGhostList), TRUE);
asrt(count($redRoom->sharedGhostList), 2);
//Can we repaint a room?
$redRoom->name = 'Yellow Room';
$id = R::store($redRoom);
$yellowRoom = R::load('room', $id);
asrt($yellowRoom->name, 'Yellow Room');
asrt(!is_null($yellowRoom), TRUE);
asrt(is_array($yellowRoom->sharedGhostList), TRUE);
asrt(count($yellowRoom->sharedGhostList), 2);
//Can we throw one ghost out?
array_pop($yellowRoom->sharedGhost);
R::store($yellowRoom);
$yellowRoom = $yellowRoom->fresh();
asrt($yellowRoom->name, 'Yellow Room');
asrt(!is_null($yellowRoom), TRUE);
asrt(is_array($yellowRoom->sharedGhostList), TRUE);
asrt(count($yellowRoom->sharedGhostList), 1);
//can we remove one of the rooms?
asrt(R::count('key'), 1);
$list = $mansion->withCondition(' "name" = ? ', array('Blue Room'))->xownRoomList;
$room = reset($list);
unset($mansion->xownRoomList[$room->id]);
R::store($mansion);
asrt(R::count('room'), 2);
//and what about its dependent beans?
asrt(R::count('key'), 0);
asrt(R::count('ghost_room'), 3);
//and can we find ghosts?
$ghosts = R::find('ghost');
asrt(count($ghosts), 4);
$ghosts = R::findAll('ghost', 'ORDER BY id');
asrt(count($ghosts), 4);
$ghosts = R::findAll('ghost', 'ORDER BY id LIMIT 2');
asrt(count($ghosts), 2);
$ghostZero = R::findOne('ghost', ' "name" = ? ', array('zero'));
asrt($ghostZero instanceof OODBBean, TRUE);
//can we create link properties on existing tables?
$blackRoom = R::dispense('room');
$blackRoom->name = 'Black Room';
$ghostZero->link('ghost_room', array('mood' => 'grumpy'))->room = $blackRoom;
R::store($ghostZero);
$ghostZero = $ghostZero->fresh();
$list = $ghostZero->sharedRoomList;
asrt(count($list), 3);
$ghostZero = $ghostZero->fresh();
$list = $ghostZero->withCondition(' ghost_room.mood = ? ', array('grumpy'))->sharedRoomList;
asrt(count($list), 1);
//can we load a batch?
$ids = R::getCol('SELECT id FROM ghost');
$ghosts = R::batch('ghost', $ids);
asrt(count($ghosts), 4);
//can we do an aggregation?
$ghosts = $greenRoom->aggr('ownGhostRoom', 'ghost', 'ghost');
asrt(count($ghosts), 2);
//can we duplicate the mansion?
asrt(R::count('mansion'), 1);
asrt(R::count('room'), 3);
asrt(R::count('ghost'), 4);
$copy = R::dup($mansion);
R::store($copy);
asrt(R::count('mansion'), 2);
asrt(R::count('room'), 5);
//black room does not belong to mansion 1
asrt(R::count('ghost'), 4);
//can we do some counting using the list?
asrt($copy->countOwn('room'), 2);
$rooms = $copy->withCondition(' "name" = ? ', array('Green Room'))->xownRoomList;
$room = reset($rooms);
asrt($room->countShared('ghost'), 2);
//Finally restore old toolbox
R::configureFacadeWithToolbox($oldToolBox);
}
示例14: readPackageCost
function readPackageCost()
{
$packageCost = R::findAll('packagecost');
return json_encode(R::exportAll($packageCost));
}
示例15: userList
/**
* Returns an array of all users
*
* @param string $orderBy Order By $orderBy ASC
*
* @return array
*/
public static function userList($orderBy = "id")
{
$a = [];
foreach (R::findAll('user', ' ORDER BY ? ASC ', [$orderBy]) as $bean) {
$a[$bean->id] = [];
foreach ($bean as $key => $value) {
$a[$bean->id][$key] = $value;
}
}
return $a;
}