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


PHP NewsModel::find方法代码示例

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


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

示例1: edit

 public function edit($id)
 {
     $news_model = new NewsModel();
     $news = $news_model->find($id);
     $user_model = new UsersModel();
     $user = $user_model->find($news['user_id']);
     $news['user_name'] = $user['name'];
     $this->assign('news', $news);
     $this->assign('action', 'save');
     $this->display('add');
 }
开发者ID:baixinxing,项目名称:ngo20map6,代码行数:11,代码来源:NewsAction.class.php

示例2: get

 function get()
 {
     $this->f3 = \Base::instance();
     $this->f3->set('AUTOLOAD', $this->f3->get('AUTOLOAD') . ';app/cortex/');
     $this->f3->set('QUIET', false);
     $this->test = new \Test();
     $dbs = array('sql' => new \DB\SQL('mysql:host=localhost;port=3306;dbname=fatfree', 'fatfree', ''));
     foreach ($dbs as $type => $db) {
         $this->f3->set('DB', $db);
         $this->currentType = $type;
         $this->roundTime = microtime(TRUE) - \Base::instance()->get('timer');
         \AuthorModel::setdown();
         \TagModel::setdown();
         \NewsModel::setdown();
         \AuthorModel::setup();
         \TagModel::setup();
         \NewsModel::setup();
         $this->insert_tags();
         $this->insert_authors();
         $this->insert_news();
         $this->insert_news();
         $news = new \NewsModel();
         // reset timer
         $this->getTime();
         //            $result = $news->find(null,array('limit'=>5000));
         //            $this->test->message($this->getTime()." hydrate 5000 records");
         //            unset($news,$result);
         //            $news = new \NewsModel();
         //            $result = $news->find(null,array('limit' => 1000));
         //            $result[0]->author->name;
         //            $this->test->message($this->getTime()." hydrate 1000 records with 1 relation fixed size");
         //			unset($result);
         $result = $news->find(null, array('limit' => 1000));
         $result[0]->tags2[0];
         $this->test->message($this->getTime() . " hydrate 1000 records with 1 relation random size");
         //            $this->test->message($this->getTime()." hydrate 1000 records with 2 relations random size");
         //            $result = $news->find('author = 11');
         //            $this->test->message($this->getTime()." find news from a specific author(11): ".count($result).' news found');
         //            $result = $news->has('author',array('mail LIKE ?','%.co.uk%'))->find();
         //            $this->test->message($this->getTime()." find news with has condition on author: ".count($result).' news found');
         //        var_dump($this->f3->get('DB')->log());
     }
     $this->f3->set('results', $this->test->results());
 }
开发者ID:ikkez,项目名称:f3-cortex,代码行数:44,代码来源:cortex_benchmark.php

示例3: run

 function run()
 {
     $test = new \Test();
     /** @var \Base $f3 */
     $f3 = \Base::instance();
     $news = new NewsModel();
     $news->load();
     $dummy = array('title' => 'copy test', 'text' => 'Lorem ipsum dolor sit amet.', 'author' => 1, 'tags' => array(3));
     $f3->set('record1', $dummy);
     $news->copyto('record2');
     $test->expect($f3->exists('record2'), 'copyto: raw record copied to hive');
     $news->reset();
     $news->copyfrom('record1');
     $test->expect($news->title = 'copy test' && ($news->text = 'Lorem ipsum dolor sit amet.'), 'copyfrom: hydrate from hive key');
     $test->expect($news->author instanceof AuthorModel && !$news->author->dry() && $news->tags instanceof \DB\CortexCollection, 'copyfrom: relations hydrated successful');
     $test->expect($news->get('author', true) == 1, 'get raw data from relational field');
     $news->reset();
     $news->copyfrom('record2', 'title;author');
     $test->expect($news->title = 'Responsive Images' && $news->get('author', true) == 2 && $news->text == NULL, 'copyfrom: limit fields with split-able string');
     $news->reset();
     $news->copyfrom('record2', array('title'));
     $test->expect($news->title = 'Responsive Images' && $news->text == NULL, 'copyfrom: limit fields by array');
     $news->reset();
     $news->copyfrom($dummy, function ($fields) {
         return array_intersect_key($fields, array_flip(array('title')));
     });
     $test->expect($news->title = 'copy test', 'copyfrom: copy from array instead of hive key');
     $test->expect($news->title = 'copy test' && $news->text == NULL, 'copyfrom: limit fields by callback function');
     $all = $news->find();
     $allTitle = $all->getAll('title');
     $test->expect(count($allTitle) == 3 && $allTitle[0] == 'Responsive Images' && $allTitle[1] == 'CSS3 Showcase' && $allTitle[2] == 'Touchable Interfaces', 'collection getAll returns all values of selected field');
     $newsByID = $all->getBy('_id');
     $test->expect(array_keys($newsByID) == array(1, 2, 3), 'collection getBy sorts by given field');
     $newsByAuthorID = $all->getBy('author', true);
     $test->expect(array_keys($newsByAuthorID) == array(2, 1) && count($newsByAuthorID[2]) == 2 && count($newsByAuthorID[1]) == 1, 'collection getBy nested sort by author');
     $allTitle = array();
     foreach ($all as $record) {
         $allTitle[] = $record->title;
     }
     $test->expect(count($allTitle) == 3 && $allTitle[0] == 'Responsive Images' && $allTitle[1] == 'CSS3 Showcase' && $allTitle[2] == 'Touchable Interfaces', 'collection is traversable');
     ///////////////////////////////////
     return $test->results();
 }
开发者ID:tysongg,项目名称:pathfinder,代码行数:43,代码来源:test_common.php

示例4: run

 function run()
 {
     $test = new \Test();
     /** @var \Base $f3 */
     $f3 = \Base::instance();
     $news = new NewsModel();
     $news->load();
     $dummy = array('title' => 'copy test', 'text' => 'Lorem ipsum dolor sit amet.', 'author' => 1, 'tags' => array(3));
     $f3->set('record1', $dummy);
     $news->copyto('record2');
     $test->expect($f3->exists('record2'), 'copyto: raw record copied to hive');
     $news->reset();
     $news->copyfrom('record1');
     $test->expect($news->title = 'copy test' && ($news->text = 'Lorem ipsum dolor sit amet.'), 'copyfrom: hydrate from hive key');
     $test->expect($news->author instanceof AuthorModel && !$news->author->dry() && $news->tags instanceof \DB\CortexCollection, 'copyfrom: relations hydrated successful');
     $test->expect($news->get('author', true) == 1, 'get raw data from relational field');
     $news->reset();
     $news->copyfrom('record2', 'title;author');
     $test->expect($news->title = 'Responsive Images' && $news->get('author', true) == 2 && $news->text == NULL, 'copyfrom: limit fields with split-able string');
     $news->reset();
     $news->copyfrom('record2', array('title'));
     $test->expect($news->title = 'Responsive Images' && $news->text == NULL, 'copyfrom: limit fields by array');
     $news->reset();
     $news->copyfrom($dummy, function ($fields) {
         return array_intersect_key($fields, array_flip(array('title')));
     });
     $test->expect($news->title = 'copy test', 'copyfrom: copy from array instead of hive key');
     $test->expect($news->title = 'copy test' && $news->text == NULL, 'copyfrom: limit fields by callback function');
     $all = $news->find();
     $allTitle = $all->getAll('title');
     $test->expect(count($allTitle) == 3 && $allTitle[0] == 'Responsive Images' && $allTitle[1] == 'CSS3 Showcase' && $allTitle[2] == 'Touchable Interfaces', 'collection getAll returns all values of selected field');
     $newsByID = $all->getBy('_id');
     $test->expect(array_keys($newsByID) == array(1, 2, 3), 'collection getBy sorts by given field');
     $newsByAuthorID = $all->getBy('author', true);
     $test->expect(array_keys($newsByAuthorID) == array(2, 1) && count($newsByAuthorID[2]) == 2 && count($newsByAuthorID[1]) == 1, 'collection getBy nested sort by author');
     $allTitle = array();
     foreach ($all as $record) {
         $allTitle[] = $record->title;
     }
     $test->expect(count($allTitle) == 3 && $allTitle[0] == 'Responsive Images' && $allTitle[1] == 'CSS3 Showcase' && $allTitle[2] == 'Touchable Interfaces', 'collection is traversable');
     $news->reset();
     $news->load();
     $r = $news->cast(null, 0);
     $test->expect($r['tags2'] == null && is_int($r['author']), 'simple cast without relations');
     $r = $news->cast(null, 1);
     $test->expect(is_array($r['tags2']) && is_array($r['author']), '1-level nested cast');
     $r = $news->cast(null, 2);
     $test->expect(is_array($r['author']['profile']), '2-level nested cast');
     $r = $news->cast(null, array('*' => 2));
     $test->expect(is_array($r['author']['profile']), '2-level nested cast, alternative');
     $r = $news->cast(null, array('*' => 0, 'author' => 0));
     $test->expect(is_array($r['author']) && $r['tags2'] == null && $r['author']['news'] == null && $r['author']['profile'] == null, 'custom cast');
     $r = $news->cast(null, array('*' => 0, 'author' => array('*' => 1)));
     $test->expect(is_array($r['author']) && $r['tags2'] == null && is_array($r['author']['news']) && is_array($r['author']['profile']), 'custom nested cast');
     $r = $news->cast(null, array('*' => 0, 'author' => array('*' => 0, 'profile' => 0)));
     $test->expect(is_array($r['author']) && $r['tags2'] == null && $r['author']['news'] == null && is_array($r['author']['profile']) && is_int($r['author']['profile']['author']), 'custom nested cast with exclusions');
     $r = $news->cast(null, array('*' => 0, 'author' => array('*' => 0, 'profile' => 1)));
     $test->expect(is_array($r['author']) && $r['tags2'] == null && $r['author']['news'] == null && is_array($r['author']['profile']) && is_array($r['author']['profile']['author']), 'custom multi-level nested cast');
     $filterA = array('foo1 = ? and bar1 = ?', 10, 20);
     $filterB = array('foo2 = ? and bar2 = ?', 30, 40);
     $filterC = array('foo3 = ? and bar3 = ?', 50, 60);
     $filter = $news->mergeFilter(array($filterA, $filterB, $filterC), 'or');
     $test->expect($filter == array('( foo1 = ? and bar1 = ? ) or ( foo2 = ? and bar2 = ? ) or ( foo3 = ? and bar3 = ? )', 10, 20, 30, 40, 50, 60), 'merge multiple filters');
     ///////////////////////////////////
     return $test->results();
 }
开发者ID:ikkez,项目名称:f3-cortex,代码行数:66,代码来源:test_common.php

示例5: run

 function run($db, $type)
 {
     $test = new \Test();
     // clear existing data
     \AuthorModel::setdown();
     \TagModel::setdown();
     \NewsModel::setdown();
     \ProfileModel::setdown();
     // setup models
     \AuthorModel::setup();
     \TagModel::setup();
     \NewsModel::setup();
     \ProfileModel::setup();
     // setup Author
     ///////////////////////////////////
     $author_id = array();
     $author = new \AuthorModel();
     $ac = $author::resolveConfiguration();
     $author_pk = is_int(strpos($type, 'sql')) ? $ac['primary'] : '_id';
     $author->name = 'Johnny English';
     $author->save();
     $author_id[] = $author->_id;
     $author->reset();
     $author->name = 'Ridley Scott';
     $author->save();
     $author_id[] = $author->_id;
     $author->reset();
     $author->name = 'James T. Kirk';
     $author->save();
     $author_id[] = $author->_id;
     $author->reset();
     $allauthors = $author->find()->castAll();
     $allauthors = $this->getResult($allauthors);
     $test->expect(json_encode($allauthors) == '[{"name":"Johnny English"},{"name":"Ridley Scott"},{"name":"James T. Kirk"}]', $type . ': all AuthorModel items created');
     // setup Tags
     ///////////////////////////////////
     $tag_id = array();
     $tag = new \TagModel();
     $tc = $tag::resolveConfiguration();
     $tag_pk = is_int(strpos($type, 'sql')) ? $tc['primary'] : '_id';
     $tag->title = 'Web Design';
     $tag->save();
     $tag_id[] = $tag->_id;
     $tag->reset();
     $tag->title = 'Responsive';
     $tag->save();
     $tag_id[] = $tag->_id;
     $tag->reset();
     $tag->title = 'Usability';
     $tag->save();
     $tag_id[] = $tag->_id;
     $tag->reset();
     $allTags = $this->getResult($tag->find());
     $test->expect(json_encode($allTags) == '[{"title":"Web Design"},{"title":"Responsive"},{"title":"Usability"}]', $type . ': all TagModel items created');
     // setup News
     ///////////////////////////////////
     $news_id = array();
     $news = new \NewsModel();
     $nc = $news::resolveConfiguration();
     $news_pk = is_int(strpos($type, 'sql')) ? $nc['primary'] : '_id';
     $news->title = 'Responsive Images';
     $news->text = 'Lorem Ipsun';
     $news->save();
     $news_id[] = $news->_id;
     $news->reset();
     $news->title = 'CSS3 Showcase';
     $news->text = 'News Text 2';
     $news->save();
     $news_id[] = $news->_id;
     $news->reset();
     $news->title = 'Touchable Interfaces';
     $news->text = 'Lorem Foo';
     $news->save();
     $news_id[] = $news->_id;
     $news->reset();
     $allnews = $this->getResult($news->find(null, array('order' => 'title')));
     $test->expect(count($allnews) == 3 && $allnews[0]['title'] == 'CSS3 Showcase' && $allnews[1]['title'] == 'Responsive Images' && $allnews[2]['title'] == 'Touchable Interfaces', $type . ': all NewsModel items created');
     // belongs-to author relation
     ///////////////////////////////////
     $author->load();
     $news->load(array($news_pk . ' = ?', $news_id[0]));
     $news->author = $author;
     $news->save();
     $news->reset();
     $news->load(array($news_pk . ' = ?', $news_id[0]));
     $test->expect($news->author->name == 'Johnny English', $type . ': belongs-to-one: author relation created');
     $news->author = NULL;
     $news->save();
     $news->reset();
     $news->load(array($news_pk . ' = ?', $news_id[0]));
     $test->expect(empty($news->author), $type . ': belongs-to-one: author relation released');
     $news->author = $author->_id;
     $news->save();
     $news->reset();
     $news->load(array($news_pk . ' = ?', $news_id[0]));
     $test->expect($news->author->name == 'Johnny English', $type . ': belongs-to-one: relation created by raw id');
     // belongs-to-many tag relation
     ///////////////////////////////////
     $tag1 = new \TagModel();
     $tag1->load(array($tag_pk . ' = ?', $tag_id[0]));
//.........这里部分代码省略.........
开发者ID:ikkez,项目名称:f3-cortex,代码行数:101,代码来源:test_relation.php

示例6: run

 function run($db, $type)
 {
     $test = new \Test();
     // setup
     ///////////////////////////////////
     $author = new \AuthorModel();
     $news = new \NewsModel();
     $profile = new \ProfileModel();
     $tag = new \TagModel();
     $ac = $author::resolveConfiguration();
     $author_pk = is_int(strpos($type, 'sql')) ? $ac['primary'] : '_id';
     $nc = $news::resolveConfiguration();
     $news_pk = is_int(strpos($type, 'sql')) ? $nc['primary'] : '_id';
     $tc = $tag::resolveConfiguration();
     $tag_pk = is_int(strpos($type, 'sql')) ? $tc['primary'] : '_id';
     $authorIDs = $author->find()->getAll('_id');
     $all = $news->find();
     $newsIDs = $all->getAll('_id');
     $profileIDs = $profile->find()->getAll('_id');
     $tagIDs = $tag->find()->getAll('_id');
     // add another relation
     $news->load(array('title = ?', 'CSS3 Showcase'));
     $news->author = $author->load(array($author_pk . ' = ?', $authorIDs[0]));
     $news->save();
     $news->reset();
     $author->reset();
     // has-filter on belongs-to relation
     ///////////////////////////////////
     $result = $author->has('news', array('title like ?', '%Image%'))->afind();
     $test->expect(count($result) == 1 && $result[0]['name'] == 'Johnny English', $type . ': has filter on many-to-one field');
     $test->expect(count($result[0]['news']) == 2 && $result[0]['news'][0]['title'] == 'Responsive Images' && $result[0]['news'][1]['title'] == 'CSS3 Showcase', $type . ': has filter does not prune relation set');
     $result = $news->has('author', array('name = ?', 'Johnny English'))->afind();
     $test->expect(count($result) == 2 && $result[0]['title'] == 'Responsive Images' && $result[1]['title'] == 'CSS3 Showcase', $type . ': has filter on one-to-many field');
     // add another profile
     $profile->message = 'Beam me up, Scotty!';
     $profile->author = $authorIDs[2];
     $profile->save();
     $profile->reset();
     $result = $author->has('profile', array('message LIKE ?', '%Scotty%'))->afind();
     $test->expect(count($result) == 1 && $result[0]['name'] == 'James T. Kirk' && $result[0]['profile']['message'] == 'Beam me up, Scotty!', $type . ': has filter on one-to-one field');
     $result = $profile->has('author', array('name LIKE ?', '%Kirk%'))->afind();
     $test->expect(count($result) == 1 && $result[0]['message'] == 'Beam me up, Scotty!' && $result[0]['author']['name'] == 'James T. Kirk', $type . ': has filter on one-to-one field, inverse');
     // add mm tags
     $news->load(array('title = ?', 'Responsive Images'));
     $news->tags2 = array($tagIDs[0], $tagIDs[1]);
     $news->save();
     $news->load(array('title = ?', 'CSS3 Showcase'));
     $news->tags2 = array($tagIDs[1], $tagIDs[2]);
     $news->save();
     $news->reset();
     $result = $news->has('tags2', array('title like ?', '%Design%'))->find();
     $test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive Images', $type . ': has filter on many-to-many field');
     $result = $news->has('tags2', array('title = ?', 'Responsive'))->find();
     $test->expect(count($result) == 2 && $result[0]['title'] == 'Responsive Images' && $result[1]['title'] == 'CSS3 Showcase', $type . ': has filter on many-to-many field, additional test');
     $result = $tag->has('news', array('title = ?', 'Responsive Images'))->find();
     $test->expect(count($result) == 2 && $result[0]['title'] == 'Web Design' && $result[1]['title'] == 'Responsive', $type . ': has filter on many-to-many field, inverse');
     // add another tag
     $news->load(array('title = ?', 'Touchable Interfaces'));
     $news->tags2 = array($tagIDs[1]);
     $news->save();
     $news->reset();
     $tag->has('news', array('text LIKE ? and title LIKE ?', '%Lorem%', '%Interface%'));
     $result = $tag->find();
     $test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive', $type . ': has filter with multiple conditions');
     $news->has('tags2', array('title = ? OR title = ?', 'Usability', 'Web Design'));
     $result = $news->afind(array('text = ?', 'Lorem Ipsun'));
     $test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive Images', $type . ': find with condition and has filter');
     $news->load(array('title = ?', 'Responsive Images'));
     $news->author = $authorIDs[1];
     $news->save();
     $news->reset();
     $news->has('tags2', array('title = ? OR title = ?', 'Usability', 'Web Design'));
     $news->has('author', array('name = ?', 'Ridley Scott'));
     $result = $news->afind();
     $test->expect(count($result) == 1 && $result[0]['title'] == 'Responsive Images', $type . ': find with multiple has filters on different relations');
     // add another news to author 2
     $news->load(array($news_pk . ' = ?', $newsIDs[2]));
     $news->author = $authorIDs[1];
     $news->save();
     $news->reset();
     $news->has('author', array('name = ?', 'Ridley Scott'));
     $news->load();
     $res = array();
     while (!$news->dry()) {
         $res[] = $news->title;
         $news->next();
     }
     $test->expect(count($res) == 2 && $res[0] == 'Responsive Images' && $res[1] == 'Touchable Interfaces', $type . ': has filter in load context');
     $news->reset();
     $news->fields(array('title'));
     $news->load();
     $test->expect(!empty($news->title) && empty($news->author) && empty($news->text) && empty($news->tags) && empty($news->tags2), $type . ': use a whitelist to restrict fields');
     unset($news);
     $news = new \NewsModel();
     $news->fields(array('title', 'tags', 'tags2', 'author'), true);
     $news->load();
     $test->expect(empty($news->title) && empty($news->author) && !empty($news->text) && empty($news->tags) && empty($news->tags2), $type . ': use a blacklist to restrict fields');
     unset($news);
     $news = new \NewsModel();
     $news->fields(array('tags.title'));
//.........这里部分代码省略.........
开发者ID:tysongg,项目名称:pathfinder,代码行数:101,代码来源:test_filter.php


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