本文整理汇总了PHP中People::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP People::findFirst方法的具体用法?PHP People::findFirst怎么用?PHP People::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类People
的用法示例。
在下文中一共展示了People::findFirst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCacheResultsetSimpleLibmemcached
public function testCacheResultsetSimpleLibmemcached()
{
require 'unit-tests/config.db.php';
if (empty($configMysql)) {
$this->markTestSkipped('Test skipped');
return;
}
if (!class_exists('Memcached')) {
$this->markTestSkipped("Memcached class does not exist, test skipped");
return;
}
$cache = $this->_getCache('Libmemcached');
$key = 'test-resultset-' . mt_rand(0, 9999);
//Single
$people = People::findFirst(array('cache' => array('key' => $key)));
$this->assertTrue(is_object($people));
$people = $cache->get($key);
$this->assertEquals(get_class($people->getFirst()), 'People');
$people = $cache->get($key);
$this->assertEquals(get_class($people->getFirst()), 'People');
//Re-get from the cache
$people = People::findFirst(array('cache' => array('key' => $key)));
$this->assertTrue(is_object($people));
$key = 'test-resultset-' . mt_rand(0, 9999);
//Multiple
$people = People::find(array('limit' => 35, 'cache' => array('key' => $key)));
$number = 0;
foreach ($people as $individual) {
$this->assertTrue(is_object($individual));
$number++;
}
$this->assertEquals($number, 35);
$people = $cache->get($key);
$this->assertEquals(get_class($people), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
$number = 0;
foreach ($people as $individual) {
$this->assertTrue(is_object($individual));
$number++;
}
$this->assertEquals($number, 35);
$people = $cache->get($key);
$this->assertEquals(get_class($people), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
//Re-get the data from the cache
$people = People::find(array('limit' => 35, 'cache' => array('key' => $key)));
$number = 0;
foreach ($people as $individual) {
$this->assertTrue(is_object($individual));
$number++;
}
$this->assertEquals($number, 35);
}
示例2: _executeTestsNormal
protected function _executeTestsNormal($di)
{
$this->_prepareDb($di->getShared('db'));
//Count tests
$this->assertEquals(People::count(), Personas::count());
$params = array();
$this->assertEquals(People::count($params), Personas::count($params));
$params = array("estado='I'");
$this->assertEquals(People::count($params), Personas::count($params));
$params = "estado='I'";
$this->assertEquals(People::count($params), Personas::count($params));
$params = array("conditions" => "estado='I'");
$this->assertEquals(People::count($params), Personas::count($params));
//Find first
$people = People::findFirst();
$this->assertTrue(is_object($people));
$this->assertEquals(get_class($people), 'People');
$persona = Personas::findFirst();
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$people = People::findFirst("estado='I'");
$this->assertTrue(is_object($people));
$persona = Personas::findFirst("estado='I'");
$this->assertTrue(is_object($persona));
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$people = People::findFirst(array("estado='I'"));
$persona = Personas::findFirst(array("estado='I'"));
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$params = array("conditions" => "estado='I'");
$people = People::findFirst($params);
$persona = Personas::findFirst($params);
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$params = array("conditions" => "estado='A'", "order" => "nombres");
$people = People::findFirst($params);
$persona = Personas::findFirst($params);
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$params = array("estado='A'", "order" => "nombres DESC", "limit" => 30);
$people = People::findFirst($params);
$persona = Personas::findFirst($params);
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$params = array("estado=?1", "bind" => array(1 => 'A'), "order" => "nombres DESC", "limit" => 30);
$people = People::findFirst($params);
$persona = Personas::findFirst($params);
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$params = array("estado=:estado:", "bind" => array("estado" => 'A'), "order" => "nombres DESC", "limit" => 30);
$people = People::findFirst($params);
$persona = Personas::findFirst($params);
$this->assertEquals($people->nombres, $persona->nombres);
$this->assertEquals($people->estado, $persona->estado);
$robot = Robots::findFirst(1);
$this->assertEquals(get_class($robot), 'Robots');
//Find tests
$personas = Personas::find();
$people = People::find();
$this->assertEquals(count($personas), count($people));
$personas = Personas::find("estado='I'");
$people = People::find("estado='I'");
$this->assertEquals(count($personas), count($people));
$personas = Personas::find(array("estado='I'"));
$people = People::find(array("estado='I'"));
$this->assertEquals(count($personas), count($people));
$personas = Personas::find(array("estado='A'", "order" => "nombres"));
$people = People::find(array("estado='A'", "order" => "nombres"));
$this->assertEquals(count($personas), count($people));
$personas = Personas::find(array("estado='A'", "order" => "nombres", "limit" => 100));
$people = People::find(array("estado='A'", "order" => "nombres", "limit" => 100));
$this->assertEquals(count($personas), count($people));
$params = array("estado=?1", "bind" => array(1 => "A"), "order" => "nombres", "limit" => 100);
$personas = Personas::find($params);
$people = People::find($params);
$this->assertEquals(count($personas), count($people));
$params = array("estado=:estado:", "bind" => array("estado" => "A"), "order" => "nombres", "limit" => 100);
$personas = Personas::find($params);
$people = People::find($params);
$this->assertEquals(count($personas), count($people));
$number = 0;
$peoples = Personas::find(array("conditions" => "estado='A'", "order" => "nombres", "limit" => 20));
foreach ($peoples as $people) {
$number++;
}
$this->assertEquals($number, 20);
$persona = new Personas($di);
$persona->cedula = 'CELL' . mt_rand(0, 999999);
$this->assertFalse($persona->save());
//Messages
$this->assertEquals(count($persona->getMessages()), 4);
$messages = array(0 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'tipo_documento_id is required', '_field' => 'tipo_documento_id')), 1 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'nombres is required', '_field' => 'nombres')), 2 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'cupo is required', '_field' => 'cupo')), 3 => ModelMessage::__set_state(array('_type' => 'PresenceOf', '_message' => 'estado is required', '_field' => 'estado')));
$this->assertEquals($persona->getMessages(), $messages);
//Save
$persona = new Personas($di);
$persona->cedula = 'CELL' . mt_rand(0, 999999);
$persona->tipo_documento_id = 1;
$persona->nombres = 'LOST';
$persona->telefono = '1';
//.........这里部分代码省略.........
示例3: testRawValue
public function testRawValue()
{
$parameters = array('conditions' => ' :rawsql: ', 'bind' => array('rawsql' => new Phalcon\Db\RawValue("estado='I'")));
$people = People::findFirst($parameters);
$this->assertTrue(is_object($people));
}