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


PHP Facade::findOne方法代码示例

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


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

示例1: testCustomBeanHelper

 /**
  * Test whether we can override the getModelForBean() method
  * of the BeanHelper and use a custom BeanHelper to attach a model
  * based on type.
  *
  * @return void
  */
 public function testCustomBeanHelper()
 {
     $customBeanHelper = new \SoupBeanHelper(R::getToolbox());
     $oldBeanHelper = R::getRedBean()->getBeanHelper();
     asrt($oldBeanHelper instanceof SimpleFacadeBeanHelper, TRUE);
     R::getRedBean()->setBeanHelper($customBeanHelper);
     $meal = R::dispense('meal');
     asrt($meal->box() instanceof \Model_Soup, TRUE);
     $cake = R::dispense('cake');
     asrt(is_null($cake->box()), TRUE);
     $bean = R::dispense('coffee');
     asrt($bean->box() instanceof \Model_Coffee, TRUE);
     $meal->setFlavour('tomato');
     asrt($meal->getFlavour(), 'tomato');
     $meal->rating = 5;
     R::store($meal);
     asrt($meal->getFlavour(), 'tomato');
     $meal = $meal->unbox();
     asrt($meal->getFlavour(), 'tomato');
     $meal = R::findOne('meal');
     asrt($meal->box() instanceof \Model_Soup, TRUE);
     asrt($meal->getFlavour(), '');
     $meal->setFlavour('tomato');
     asrt($meal->getFlavour(), 'tomato');
     $meal = $meal->unbox();
     asrt($meal->getFlavour(), 'tomato');
     R::getRedBean()->setBeanHelper($oldBeanHelper);
 }
开发者ID:diego-vieira,项目名称:redbean,代码行数:35,代码来源:Fuse.php

示例2: testAutoClearHistory

 /**
  * Test whether we can set the 'auto clear'
  * option in OODB.
  *
  * @return void
  */
 public function testAutoClearHistory()
 {
     testpack('Auto clear history');
     $book = R::dispense('book');
     $book->pages = 100;
     $book->title = 'book';
     R::store($book);
     $book = R::findOne('book');
     asrt($book->hasChanged('title'), FALSE);
     $book->title = 'yes';
     R::store($book);
     asrt($book->hasChanged('title'), TRUE);
     OODB::autoClearHistoryAfterStore(TRUE);
     $book = R::findOne('book');
     asrt($book->hasChanged('title'), FALSE);
     $book->title = 'yes2';
     R::store($book);
     asrt($book->hasChanged('title'), FALSE);
     OODB::autoClearHistoryAfterStore(FALSE);
     $book = R::findOne('book');
     asrt($book->hasChanged('title'), FALSE);
     $book->title = 'yes';
     R::store($book);
     asrt($book->hasChanged('title'), TRUE);
 }
开发者ID:simirimia,项目名称:redbean,代码行数:31,代码来源:Misc.php

示例3: login

 /**
  * Logs admin into the system
  * @param $login
  * @param $password
  * @return \SkullyAdmin\Models\Admin|null
  */
 public function login($login, $password)
 {
     /** @var \RedBean_SimpleModel $adminBean */
     $adminBean = R::findOne('admin', "status = ? and email = ?", array(Admin::STATUS_ACTIVE, $login));
     if (!empty($adminBean)) {
         /** @var \SkullyAdmin\Models\Admin $admin */
         $admin = $adminBean->box();
         if ($admin->get('password_hash') == UtilitiesHelper::toHash($password, $admin->get('salt'), $this->app->config('globalSalt'))) {
             $adminSessions = R::find('adminsession', "admin_id = ?", array($admin->getID()));
             if (!empty($adminSessions)) {
                 R::trashAll($adminSessions);
             }
             // when everything ok, regenerate session
             session_regenerate_id(true);
             // change session ID for the current session and invalidate old session ID
             $adminId = $admin->getID();
             $sessionId = session_id();
             $adminsession = $this->app->createModel('adminsession', array("admin_id" => $adminId, "session_id" => $sessionId));
             $this->app->getSession()->set('adminId', $admin->getID());
             R::store($adminsession);
             return $admin;
         }
     }
     return null;
 }
开发者ID:skullyframework,项目名称:skully-admin,代码行数:31,代码来源:AdminRepository.php

示例4: uploadImage

 public function uploadImage()
 {
     $error = '';
     $uploadedImages = array();
     if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
         // Find instance
         $id = $this->getParam($this->instanceName . '_id');
         if (!empty($id)) {
             /** @var \RedbeanPHP\SimpleModel $instanceBean */
             $instanceBean = R::findOne($this->model(), 'id = ?', array($id));
             /** @var \Skully\App\Models\Setting $instance */
             $instance = $instanceBean->box();
         } else {
             $instance = null;
         }
         try {
             $uploadedImages = $this->processUploadedImage($instance, $this->getParam('settingName'));
         } catch (\Exception $e) {
             $error = $e->getMessage();
         }
     }
     if (!empty($error)) {
         echo json_encode(array('error' => $error));
     } else {
         echo json_encode($uploadedImages);
     }
 }
开发者ID:skullyframework,项目名称:skully-admin,代码行数:27,代码来源:ImageUploaderCRUD.php

示例5: testCreateAdmin

 public function testCreateAdmin()
 {
     $this->migrate();
     $admin = $this->app->createModel('admin', array('name' => 'Admin', 'email' => 'admin@skullyframework.com', 'password' => 'lepass', 'password_confirmation' => 'lepass', 'status' => Admin::STATUS_ACTIVE));
     R::store($admin);
     $bean = R::findOne('admin', 'name = ?', array('Admin'));
     $this->assertEquals($bean->name, $admin->get('name'));
 }
开发者ID:skullyframework,项目名称:skully-admin,代码行数:8,代码来源:TestAdminCreation.php

示例6: equipe

function equipe($slug)
{
    global $twig, $base, $titre;
    $personne = R::findOne("personnes", "slug = ?", [$slug]);
    if (!$personne) {
        return not_found();
    }
    return $twig->render("equipe.html", compact("base", "titre", "personne"));
}
开发者ID:HE-Arc,项目名称:php-intro-framework,代码行数:9,代码来源:index.php

示例7: getAdmin

 public function getAdmin()
 {
     /** @var \RedBean_SimpleModel $adminBean */
     $adminBean = R::findOne('admin', "id = ?", array($this->getSession()->get('adminId')));
     if (!empty($adminBean)) {
         return $adminBean->box();
     } else {
         return null;
     }
 }
开发者ID:skullyframework,项目名称:project,代码行数:10,代码来源:Application.php

示例8: testIssue259

 /**
  * Test to make sure stash cache works with recursively opening models
  * with FUSE.
  *
  * @return void
  */
 public function testIssue259()
 {
     testpack('Testing Issue #259 - Stash Cache breaks model delegation in open().');
     $mother = R::dispense('mother');
     $mother->desc = 'I am mother';
     R::store($mother);
     $child = R::dispense('child');
     $child->mother = $mother;
     $child->desc = 'I am child';
     $id = R::store($child);
     R::findOne('child', ' id = ?', array($id));
     R::find('child', ' id = ? ', array($id));
     R::load('child', $id);
 }
开发者ID:gabordemooij,项目名称:redbean,代码行数:20,代码来源:Issue259.php

示例9: testBindings

 /**
  * Test Null bindings.
  */
 public function testBindings()
 {
     R::nuke();
     $book = R::dispense('book');
     $book->content = NULL;
     //can we store a NULL?
     asrt(is_null($book->content), TRUE);
     R::store($book);
     //did we really store the NULL value ?
     $book = R::findOne('book', ' content IS NULL ');
     asrt($book instanceof OODBBean, TRUE);
     //still NULL, not empty STRING ?
     asrt(is_null($book->content), TRUE);
     $book->pages = 100;
     R::store($book);
     //did we save it once again as NULL?
     $book = R::findOne('book', ' content IS NULL ');
     asrt($book instanceof OODBBean, TRUE);
     asrt(is_null($book->content), TRUE);
     asrt(gettype($book->pages), 'string');
     $otherBook = R::dispense('book');
     $otherBook->pages = 99;
     //also if the column is VARCHAR-like?
     $otherBook->content = 'blah blah';
     R::store($otherBook);
     $book = R::findOne('book', ' content IS NULL ');
     asrt($book instanceof OODBBean, TRUE);
     asrt(is_null($book->content), TRUE);
     asrt(intval($book->pages), 100);
     //can we query not NULL as well?
     $book = R::findOne('book', ' content IS NOT NULL ');
     asrt($book instanceof OODBBean, TRUE);
     asrt(is_null($book->content), FALSE);
     asrt(intval($book->pages), 99);
     asrt($book->content, 'blah blah');
     //Can we bind NULL directly?
     $book->isGood = FALSE;
     //Is NULL the default? And... no confusion with boolean FALSE?
     R::store($book);
     $book = R::findOne('book', ' is_good IS NULL');
     asrt($book instanceof OODBBean, TRUE);
     asrt(is_null($book->content), TRUE);
     asrt(intval($book->pages), 100);
     $book = R::findOne('book', ' is_good = ?', array(0));
     asrt($book instanceof OODBBean, TRUE);
     asrt(is_null($book->content), FALSE);
     asrt(intval($book->pages), 99);
 }
开发者ID:diego-vieira,项目名称:redbean,代码行数:51,代码来源:Xnull.php

示例10: 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');
 }
开发者ID:diego-vieira,项目名称:redbean,代码行数:52,代码来源:Issue408.php

示例11: getSessionModel

 /**
  * @return \Skully\App\Models\Session
  */
 public function getSessionModel()
 {
     //read session with current session id
     // todo: empty($this->sessionModel) is required to keep connection to db as low as possible,
     //       but somehow enabling this make session disappears on new page.
     //        if(empty($this->sessionModel)){
     //echo "try to find with session id: ". session_id() . "\n";
     $sessionId = session_id();
     $sessionBean = R::findOne('session', "session_id = ?", array($sessionId));
     if (empty($sessionBean)) {
         //echo "create with session id: ". session_id()."\n";
         $this->sessionModel = $this->app->createModel('session', array("session_id" => $sessionId));
         R::store($this->sessionModel);
         //echo "after creation, session model is".get_class($this->sessionModel)."\n";
     } else {
         $this->sessionModel = $sessionBean->box();
     }
     //        }
     //        else {
     //echo "this sessionModel not empty, data is ".$this->sessionModel->get('data');
     //        }
     return $this->sessionModel;
 }
开发者ID:skullyframework,项目名称:skully,代码行数:26,代码来源:DBSession.php

示例12: 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);
 }
开发者ID:diego-vieira,项目名称:redbean,代码行数:48,代码来源:Prefixes.php

示例13:

    $cost_sheet = R::dispense('costsheet');
    $cost_sheet->month = $faker->month;
    $cost_sheet->visitor = R::findOne('visitor', 'id=?', [$faker->numberBetween($min = 1, $max = 540)]);
    $cost_sheet->status = R::findOne('status', 'id=?', [$faker->numberBetween($min = 1, $max = 5)]);
    $cost_sheet->justification_number = $faker->randomDigitNotNull;
    $cost_sheet->valid_amount = $faker->randomNumber($nbDigits = 3);
    $cost_sheet->modification_date = $faker->dateTime($max = 'now');
    R::store($cost_sheet);
}
for ($i = 0; $i < 20; $i++) {
    $package_cost = R::dispense('packagecost');
    $package_cost->libelle = $faker->realText($maxNbChars = 20, $indexSize = 2);
    $package_cost->amount = $faker->randomNumber($nbDigits = 3);
    R::store($package_cost);
}
for ($i = 0; $i < 1000; $i++) {
    $outpackage_line = R::dispense('outpackageline');
    $outpackage_line->date = $faker->dateTime($max = 'now');
    $outpackage_line->cost_sheet = R::findOne('costsheet', 'id=?', [$faker->numberBetween($min = 1, $max = 12960)]);
    $outpackage_line->amount = $faker->randomNumber($nbDigits = 3);
    $outpackage_line->libelle = $faker->realText($maxNbChars = 20, $indexSize = 2);
    R::store($outpackage_line);
}
for ($i = 0; $i < 129600; $i++) {
    $package_line = R::dispense('packageline');
    $package_line->package_cost = R::findOne('packagecost', 'id=?', [$faker->numberBetween($min = 1, $max = 20)]);
    $package_line->cost_sheet = R::findOne('costsheet', 'id=?', [$faker->numberBetween($min = 1, $max = 12960)]);
    $package_line->month = $faker->month;
    $package_line->quantity = $faker->randomNumber($nbDigits = 3);
    R::store($package_line);
}
开发者ID:pierrerispal,项目名称:ppe_gsb_API_cost_managment,代码行数:31,代码来源:create_db.php

示例14: 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"));
 }
开发者ID:cesium147,项目名称:redbean,代码行数:75,代码来源:Facade.php

示例15: testFunctionFilters

 /**
  * Test Facade bind function method.
  * Test for MySQL WKT spatial format.
  */
 public function testFunctionFilters()
 {
     R::nuke();
     R::bindFunc('read', 'location.point', 'asText');
     R::bindFunc('write', 'location.point', 'GeomFromText');
     R::store(R::dispense('location'));
     R::freeze(true);
     try {
         R::find('location');
         fail();
     } catch (SQL $exception) {
         pass();
     }
     R::freeze(false);
     try {
         R::find('location');
         pass();
     } catch (SQL $exception) {
         fail();
     }
     $location = R::dispense('location');
     $location->point = 'POINT(14 6)';
     R::store($location);
     $columns = R::inspect('location');
     asrt($columns['point'], 'point');
     $location = $location->fresh();
     asrt($location->point, 'POINT(14 6)');
     R::nuke();
     $location = R::dispense('location');
     $location->point = 'LINESTRING(0 0,1 1,2 2)';
     R::store($location);
     $columns = R::inspect('location');
     asrt($columns['point'], 'linestring');
     $location->bustcache = 2;
     R::store($location);
     $location = $location->fresh();
     asrt($location->point, 'LINESTRING(0 0,1 1,2 2)');
     R::nuke();
     $location = R::dispense('location');
     $location->point = 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))';
     R::store($location);
     $columns = R::inspect('location');
     asrt($columns['point'], 'polygon');
     $location->bustcache = 4;
     R::store($location);
     $location = $location->fresh();
     asrt($location->point, 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))');
     R::bindFunc('read', 'location.point', NULL);
     $location->bustcache = 1;
     R::store($location);
     $location = $location->fresh();
     asrt($location->point === 'POLYGON((0 0,10 0,10 10,0 10,0 0),(5 5,7 5,7 7,5 7,5 5))', FALSE);
     $filters = AQueryWriter::getSQLFilters();
     asrt(is_array($filters), TRUE);
     asrt(count($filters), 2);
     asrt(isset($filters[QueryWriter::C_SQLFILTER_READ]), TRUE);
     asrt(isset($filters[QueryWriter::C_SQLFILTER_WRITE]), TRUE);
     R::bindFunc('read', 'place.point', 'asText');
     R::bindFunc('write', 'place.point', 'GeomFromText');
     R::bindFunc('read', 'place.line', 'asText');
     R::bindFunc('write', 'place.line', 'GeomFromText');
     R::nuke();
     $place = R::dispense('place');
     $place->point = 'POINT(13.2 666.6)';
     $place->line = 'LINESTRING(9.2 0,3 1.33)';
     R::store($place);
     $columns = R::inspect('place');
     asrt($columns['point'], 'point');
     asrt($columns['line'], 'linestring');
     $place = R::findOne('place');
     asrt($place->point, 'POINT(13.2 666.6)');
     asrt($place->line, 'LINESTRING(9.2 0,3 1.33)');
     R::bindFunc('read', 'place.point', NULL);
     R::bindFunc('write', 'place.point', NULL);
     R::bindFunc('read', 'place.line', NULL);
     R::bindFunc('write', 'place.line', NULL);
 }
开发者ID:AntonyAntonio,项目名称:phpback,代码行数:81,代码来源:Writer.php


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