當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Robots::count方法代碼示例

本文整理匯總了PHP中Robots::count方法的典型用法代碼示例。如果您正苦於以下問題:PHP Robots::count方法的具體用法?PHP Robots::count怎麽用?PHP Robots::count使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Robots的用法示例。


在下文中一共展示了Robots::count方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: DI

<?php

use Phalcon\DI, Phalcon\Db\Adapter\Pdo\Sqlite as Connection, Phalcon\Mvc\Model\Manager as ModelsManager, Phalcon\Mvc\Model\Metadata\Memory as MetaData, Phalcon\Mvc\Model;
$di = new DI();
//Setup a connection
$di->set('db', new Connection(array("dbname" => "sample.db")));
//Set a models manager
$di->set('modelsManager', new ModelsManager());
//Use the memory meta-data adapter or other
$di->set('modelsMetadata', new MetaData());
//Create a model
class Robots extends Model
{
}
//Use the model
echo Robots::count();
開發者ID:aodkrisda,項目名稱:phalcon-code,代碼行數:16,代碼來源:models-3053.php

示例2:

<?php

//How many robots are there?
$number = Robots::count();
echo "There are ", $number, "\n";
//How many mechanical robots are there?
$number = Robots::count("type='mechanical'");
echo "There are ", $number, " mechanical robots\n";
開發者ID:aodkrisda,項目名稱:phalcon-code,代碼行數:8,代碼來源:Phalcon_Mvc_Model-341.php

示例3: _testCacheDefaultDI

 protected function _testCacheDefaultDI($di)
 {
     $di->set('modelsCache', function () {
         $frontCache = new Phalcon\Cache\Frontend\Data();
         return new Phalcon\Cache\Backend\File($frontCache, array('cacheDir' => 'unit-tests/cache/'));
     }, true);
     //Find
     $robots = Robots::find(array('cache' => array('key' => 'some'), 'order' => 'id'));
     $this->assertEquals(count($robots), 3);
     $this->assertTrue($robots->isFresh());
     $robots = Robots::find(array('cache' => array('key' => 'some'), 'order' => 'id'));
     $this->assertEquals(count($robots), 3);
     $this->assertFalse($robots->isFresh());
     //TODO: I really can't understand why postgresql fails on inserting a simple record
     //The error is "Object not in prerequisite state: 7 ERROR:
     //currval of sequence "robots_id_seq" is not yet defined in this session"
     //Is the ORM working with postgresql, is the database structure incorrect or
     //I'm using the wrong code?
     //Skip this test until someone can shed some light on this
     if (!$di->get("db") instanceof Phalcon\Db\Adapter\Pdo\Postgresql) {
         //Aggregate functions like sum, count, etc
         $robotscount = Robots::count(array('cache' => array('key' => 'some-count')));
         $this->assertEquals($robotscount, 3);
         //Create a temporary robot to test if the count is cached or fresh
         $newrobot = new Robots();
         $newrobot->name = "Not cached robot";
         $newrobot->type = "notcached";
         $newrobot->year = 2014;
         $newrobot->datetime = '2015-03-05 04:16:17';
         $newrobot->text = 'Not cached robot';
         $newrobot->create();
         $robotscount = Robots::count(array('cache' => array('key' => 'some-count')));
         $this->assertEquals($robotscount, 3);
         //Delete the temp robot
         Robots::findFirst("type = 'notcached'")->delete();
     }
 }
開發者ID:lisong,項目名稱:cphalcon,代碼行數:37,代碼來源:ModelsResultsetCacheTest.php

示例4:

<?php

echo 'There are ', Robots::count(), ' robots';
開發者ID:aodkrisda,項目名稱:phalcon-code,代碼行數:3,代碼來源:Phalcon_Mvc_Collection-384.php


注:本文中的Robots::count方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。