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


PHP R::findOrDispense方法代码示例

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


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

示例1: delete

 public function delete($args)
 {
     $posttype = array_shift($args);
     $id = array_shift($args);
     $post = current(R::findOrDispense('post', 'id = :id', ['id' => $id]));
     if ($post->getID()) {
         R::trash($post);
     }
     $this->redirect(PACKAGE_URL . "posts/view/{$posttype}");
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:10,代码来源:posts.php

示例2: create_field

 function create_field($post_type, $field_name, $field_type, $show_on_front = false)
 {
     $post_meta = current(R::findOrDispense('postmeta', 'post_type = :posttype AND fieldname = :field', ['posttype' => $post_type, 'field' => $field_name]));
     if (!$post_meta->getID()) {
         $post_meta->post_type = $post_type;
         $post_meta->fieldname = $field_name;
     }
     $post_meta->type = $field_type;
     $post_meta->show_on_front = $show_on_front;
     R::store($post_meta);
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:11,代码来源:post_model.php

示例3: create

 public function create($filename, \App_Config_Ini $config, $template, $mtime)
 {
     //Add the meta config to this config
     $meta_config = $this->get_meta_config();
     //First load the page that matches the slug
     $existing = current(R::findOrDispense('page', 'slug = :slug', ['slug' => $config->page->slug]));
     if ($existing->getID() && $existing->gen_filename != $filename) {
         throw new Exception("A page already exists inside the database with the same slug but built with the onscreen page creator");
         return false;
     }
     $page = current(R::findOrDispense('page', 'gen_filename = :file', ['file' => $filename]));
     /* @var $page \RedBeanPHP\OODBBean */
     /**
      * Creates the page database object
      */
     if (!$page->getID()) {
         // The Page does not exist
         $page->gen_filename = $filename;
         $page->title = $config->page->title;
         $page->description = $config->page->description;
     } else {
         $old_slug = $page->slug;
         $meta = new Meta_Generator($meta_config);
         $page->title = !empty($config->page->title) ? $config->page->title : $meta->get_title($page->slug);
         $page->description = !empty($config->page->description) ? $config->page->description : $meta->get_description($page->slug);
     }
     $page->slug = $config->page->slug;
     $page->layout = $this->theme->load_layout($config->page->layout ? $config->page->layout : 'layouts.default.twig', $this->theme->theme)->file;
     /*
      * Create the template file in the theme
      */
     $page->template = $this->theme->generate_template($filename, $template, $mtime);
     R::store($page);
     // Create a route for this page for loading
     $r_func = function ($slug) use($page) {
         //Load the front end instance loader
         $theme = Theme_Loader::get_instance();
         $theme->set_theme(THEME);
         G2_User::init();
         if (G()->logged_in()) {
             $theme->logged_in();
         }
         $_SESSION['theme'] = $theme;
         //Render the theme
         if ($theme->page_exists($page->slug)) {
             $theme->render($page->slug);
         }
     };
     $route = new Router();
     if (isset($old_slug)) {
         $route->delete_route($old_slug);
     }
     $route->create_route($page->slug, $r_func);
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:54,代码来源:Page.php

示例4: create_route

 function create_route($slug, $callable, $allow_params = false)
 {
     // Create the route in the database
     //Serialize the callable object
     $serializer = new Serializer();
     $s_closure = $serializer->serialize($callable);
     $hash = md5($s_closure);
     if (R::findOne('route', 'hash = :hash', ['hash' => $hash])) {
         return;
     }
     $route = current(R::findOrDispense('route', 'slug = :slug', ['slug' => $slug]));
     $route->hash = $hash;
     $route->slug = $slug;
     $route->closure = $s_closure;
     $route->allow_params = $allow_params;
     R::store($route);
     // Store
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:18,代码来源:Router.php

示例5: page_crud

 function page_crud()
 {
     if (!empty($_POST)) {
         //Load an existing page if it exists
         $page = current(R::findOrDispense('page', 'id = :id', ['id' => $_POST['page_id']]));
         if (!$page->getID()) {
             $page->slug = $_POST['slug'];
         } else {
             $old = clone $page;
         }
         $page->description = $_POST['description'];
         $page->title = $_POST['title'];
         $page->template = $_POST['template'];
         $page->layout = $_POST['layout'];
         R::store($page);
         Audit::create($old, $page, 'Page details Saved');
         $this->redirect(BASE_URL . $page->slug);
     }
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:19,代码来源:crud.php

示例6: load

 function load()
 {
     $c = $this->c();
     if ($this->replace_content_only) {
         $starting_html = $c->html();
     } else {
         $starting_html = $c->saveHTML();
     }
     $page_id = $this->area->page->id;
     $area_name = $this->area->area_name;
     $field_type = $this->c()->getAttribute('mvc-type') ? $this->c()->getAttribute('mvc-type') : 'default';
     //$starting_html = $this->area->html;
     $this->area = current(R::findOrDispense('area', 'page_id = :page AND area_name = :field AND type = :type', ['page' => $page_id, 'field' => $area_name, 'type' => $field_type]));
     if (!$this->area->getID()) {
         $this->area->area_name = $area_name;
         $this->area->html = $starting_html;
         $this->area->type = $field_type;
         $this->area->page = R::load('page', $page_id);
         $this->save();
     }
     return $this->area;
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:22,代码来源:Default.php

示例7: create_pages

 public function create_pages()
 {
     //Load Page files
     $files = Mvc_Functions::directoryToArray($this->theme . "/pages", true);
     //		var_dump($files);exit;
     //Loop throught the files and read theme seperately
     foreach ($files as $file) {
         if (is_dir($file)) {
             continue;
         }
         $id = $file . "-" . BASE_URL;
         //Check file last modified before loading
         $file_mod_time = current(R::findOrDispense('filem', 'filename = :file', ['file' => $id]));
         if (!$file_mod_time->getID()) {
             $file_mod_time->filename = $id;
             $file_mod_time->last_modified = filemtime($file);
             R::store($file_mod_time);
         } else {
             //				debug($file . ' === ' . filemtime($file) . ' ' . $file_mod_time->last_modified);
             if (filemtime($file) > $file_mod_time->last_modified) {
                 $file_mod_time->last_modified = filemtime($file);
                 R::store($file_mod_time);
             } else {
                 continue;
             }
         }
         list($config, $template) = explode("==", file_get_contents($file));
         list($config, $template) = preg_split('/(==\\n)|(==\\r)/', file_get_contents($file));
         //						parent::$lines = preg_split('/\r\n|\n|\r/', trim(file_get_contents('file.txt')));
         $config = new App_Config_Ini($config);
         if ($config->type) {
             $classname = "Theme_Type_" . ucfirst($config->type);
             if (class_exists($classname)) {
                 $class = new $classname($this);
                 if ($class instanceof Theme_Type) {
                     $class->create($file, $config, $template, filemtime($file));
                 }
             }
         } else {
             $class = new Theme_Type_Page($this);
             $class->create($file, $config, $template, filemtime($file));
         }
     }
     //Remove all pages saved in database that does not exist inside the pages folder
     $this->remove_old_pages();
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:46,代码来源:Loader.php

示例8: load_area_oild

 function load_area_oild($id, $area_name, $field_type, $starting_html)
 {
     $bean = current(R::findOrDispense('area', 'layout_id = :layout AND area_name = :field', ['layout' => $id, 'field' => $area_name]));
     if (!$bean->getID()) {
         $bean->area_name = $area_name;
         $bean->html = $starting_html;
         $bean->type = $field_type;
         $bean->page_id = $this->page->id;
         $this->layout->ownArea[] = $bean;
         R::store($this->layout);
     }
     return $bean;
 }
开发者ID:g2design,项目名称:g2-modules,代码行数:13,代码来源:LayoutProcess.php

示例9: testFinding

 /**
  * Begin testing.
  * This method runs the actual test pack.
  * 
  * @return void
  */
 public function testFinding()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     $a = new RedBean_AssociationManager($toolbox);
     $page = $redbean->dispense("page");
     $page->name = "John's page";
     $idpage = $redbean->store($page);
     $page2 = $redbean->dispense("page");
     $page2->name = "John's second page";
     $idpage2 = $redbean->store($page2);
     $a->associate($page, $page2);
     $pageOne = $redbean->dispense("page");
     $pageOne->name = "one";
     $pageMore = $redbean->dispense("page");
     $pageMore->name = "more";
     $pageEvenMore = $redbean->dispense("page");
     $pageEvenMore->name = "evenmore";
     $pageOther = $redbean->dispense("page");
     $pageOther->name = "othermore";
     set1toNAssoc($a, $pageOther, $pageMore);
     set1toNAssoc($a, $pageOne, $pageMore);
     set1toNAssoc($a, $pageOne, $pageEvenMore);
     asrt(count($redbean->find("page", array(), " name LIKE '%more%' ", array())), 3);
     asrt(count($redbean->find("page", array(), " name LIKE :str ", array(":str" => '%more%'))), 3);
     asrt(count($redbean->find("page", array(), array(" name LIKE :str ", array(":str" => '%more%')))), 3);
     asrt(count($redbean->find("page", array(), " name LIKE :str ", array(":str" => '%mxore%'))), 0);
     asrt(count($redbean->find("page", array("id" => array(2, 3)))), 2);
     $bean = $redbean->dispense("wine");
     $bean->name = "bla";
     for ($i = 0; $i < 10; $i++) {
         $redbean->store($bean);
     }
     $redbean->find("wine", array("id" => 5));
     //  Finder:where call RedBean_OODB::convertToBeans
     $bean2 = $redbean->load("anotherbean", 5);
     asrt($bean2->id, 0);
     $keys = $adapter->getCol("SELECT id FROM page WHERE " . $writer->esc('name') . " LIKE '%John%'");
     asrt(count($keys), 2);
     $pages = $redbean->batch("page", $keys);
     asrt(count($pages), 2);
     $p = R::findLast('page');
     pass();
     $row = R::getRow('select * from page ');
     asrt(is_array($row), TRUE);
     asrt(isset($row['name']), TRUE);
     // Test findAll -- should not throw an exception
     asrt(count(R::findAll('page')) > 0, TRUE);
     asrt(count(R::findAll('page', ' ORDER BY id ')) > 0, TRUE);
     $beans = R::findOrDispense("page");
     asrt(count($beans), 6);
     asrt(is_null(R::findLast('nothing')), TRUE);
     try {
         R::find('bean', ' id > 0 ', 'invalid bindings argument');
         fail();
     } catch (RedBean_Exception_Security $exception) {
         pass();
     }
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:68,代码来源:Finding.php

示例10: array

try {
    R::exec("select * from job limit ? ", array(1));
    pass();
} catch (Exception $e) {
    fail();
}
try {
    R::exec("select * from job limit :l ", array(":l" => 1));
    pass();
} catch (Exception $e) {
    fail();
}
testpack("Test findOrDispense");
$person = R::findOrDispense("person", " job = ? ", array("developer"));
asrt(count($person) > 0, true);
$person = R::findOrDispense("person", " job = ? ", array("musician"));
asrt(count($person) > 0, true);
$musician = array_pop($person);
asrt(intval($musician->id), 0);
testpack("Test count and wipe");
$page = R::dispense("page");
$page->name = "ABC";
R::store($page);
$n1 = R::count("page");
$page = R::dispense("page");
$page->name = "DEF";
R::store($page);
$n2 = R::count("page");
asrt($n1 + 1, $n2);
R::wipe("page");
asrt(R::count("page"), 0);
开发者ID:ryjkov,项目名称:redbean,代码行数:31,代码来源:test.php

示例11: testPDOParameterBinding

 /**
  * Test parameter binding with PDO.
  * 
  * @return void
  */
 public function testPDOParameterBinding()
 {
     $toolbox = R::$toolbox;
     $adapter = $toolbox->getDatabaseAdapter();
     $writer = $toolbox->getWriter();
     $redbean = $toolbox->getRedBean();
     $pdo = $adapter->getDatabase();
     R::$adapter->getDatabase()->setUseStringOnlyBinding(TRUE);
     try {
         R::getAll("select * from job limit ? ", array(1));
         fail();
     } catch (Exception $e) {
         pass();
     }
     try {
         R::getAll("select * from job limit :l ", array(":l" => 1));
         fail();
     } catch (Exception $e) {
         pass();
     }
     try {
         R::exec("select * from job limit ? ", array(1));
         fail();
     } catch (Exception $e) {
         pass();
     }
     try {
         R::exec("select * from job limit :l ", array(":l" => 1));
         fail();
     } catch (Exception $e) {
         pass();
     }
     R::$adapter->getDatabase()->setUseStringOnlyBinding(FALSE);
     try {
         R::getAll("select * from job limit ? ", array(1));
         pass();
     } catch (Exception $e) {
         print_r($e);
         fail();
     }
     try {
         R::getAll("select * from job limit :l ", array(":l" => 1));
         pass();
     } catch (Exception $e) {
         fail();
     }
     try {
         R::exec("select * from job limit ? ", array(1));
         pass();
     } catch (Exception $e) {
         fail();
     }
     try {
         R::exec("select * from job limit :l ", array(":l" => 1));
         pass();
     } catch (Exception $e) {
         fail();
     }
     testpack("Test findOrDispense");
     $person = R::findOrDispense("person", " job = ? ", array("developer"));
     asrt(count($person) > 0, TRUE);
     $person = R::findOrDispense("person", " job = ? ", array("musician"));
     asrt(count($person) > 0, TRUE);
     $musician = array_pop($person);
     asrt(intval($musician->id), 0);
     try {
         $adapter->exec("an invalid query");
         fail();
     } catch (RedBean_Exception_SQL $e) {
         pass();
     }
     asrt((int) $adapter->getCell("SELECT 123"), 123);
     asrt((int) $adapter->getCell("SELECT ?", array("987")), 987);
     asrt((int) $adapter->getCell("SELECT ?+?", array("987", "2")), 989);
     asrt((int) $adapter->getCell("SELECT :numberOne+:numberTwo", array(":numberOne" => 42, ":numberTwo" => 50)), 92);
     $pair = $adapter->getAssoc("SELECT 'thekey','thevalue' ");
     asrt(is_array($pair), TRUE);
     asrt(count($pair), 1);
     asrt(isset($pair["thekey"]), TRUE);
     asrt($pair["thekey"], "thevalue");
     testpack('Test whether we can properly bind and receive NULL values');
     asrt($adapter->getCell('SELECT :nil ', array(':nil' => 'NULL')), 'NULL');
     asrt($adapter->getCell('SELECT :nil ', array(':nil' => NULL)), NULL);
     asrt($adapter->getCell('SELECT ? ', array('NULL')), 'NULL');
     asrt($adapter->getCell('SELECT ? ', array(NULL)), NULL);
 }
开发者ID:daviddeutsch,项目名称:redbean-adaptive,代码行数:91,代码来源:Parambind.php


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