本文整理汇总了PHP中People::find方法的典型用法代码示例。如果您正苦于以下问题:PHP People::find方法的具体用法?PHP People::find怎么用?PHP People::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类People
的用法示例。
在下文中一共展示了People::find方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: postDesv
/**
* Show the form for creating a new resource.
* @param Request $request
* @return Response
*/
public function postDesv(Request $request)
{
$ids = $request->get('people');
if ($ids != null) {
$branch = Branch::findOrFail($request->get('branch'));
$branch->people()->detach($ids);
for ($i = 0; $i < count($ids); $i++) {
$user = People::find($ids[$i])->user;
$user->roles()->detach();
}
flash()->success('Se han desviculado (' . count($ids) . ') personas de la sucursal ' . $branch->name);
} else {
$branch = Branch::findOrFail($request->get('branch'));
flash()->overlay('No se encontraron personas para desvincular de la sucursal ' . $branch->name . '.', 'Notificacion de errores');
}
return view('admin.showpeople', compact('branch'));
}
示例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: _executeTestsNormal
protected function _executeTestsNormal($di)
{
//Where
$personas = Personas::query()->where("estado='I'")->execute();
$people = People::find("estado='I'");
$this->assertEquals(count($personas), count($people));
$personas = Personas::query()->conditions("estado='I'")->execute();
$people = People::find("estado='I'");
$this->assertEquals(count($personas), count($people));
$personas = Personas::query()->where("estado='A'")->orderBy("nombres")->execute();
$people = People::find(array("estado='A'", "order" => "nombres"));
$this->assertEquals(count($personas), count($people));
$somePersona = $personas->getFirst();
$somePeople = $people->getFirst();
$this->assertEquals($somePersona->cedula, $somePeople->cedula);
//Where + Order + limit
$personas = Personas::query()->where("estado='A'")->orderBy("nombres")->limit(100)->execute();
$people = People::find(array("estado='A'", "order" => "nombres", "limit" => 100));
$this->assertEquals(count($personas), count($people));
$somePersona = $personas->getFirst();
$somePeople = $people->getFirst();
$this->assertEquals($somePersona->cedula, $somePeople->cedula);
//Where with bind params + order + Limit
$personas = Personas::query()->where("estado=?1")->bind(array(1 => "A"))->orderBy("nombres")->limit(100)->execute();
$people = People::find(array("estado=?1", "bind" => array(1 => "A"), "order" => "nombres", "limit" => 100));
$this->assertEquals(count($personas), count($people));
$somePersona = $personas->getFirst();
$somePeople = $people->getFirst();
$this->assertEquals($somePersona->cedula, $somePeople->cedula);
//Where with bind params + order + limit + Offset
$personas = Personas::query()->where("estado=?1")->bind(array(1 => "A"))->orderBy("nombres")->limit(100, 10)->execute();
$people = People::find(array("estado=?1", "bind" => array(1 => "A"), "order" => "nombres", "limit" => array('number' => 100, 'offset' => 10)));
$this->assertEquals(count($personas), count($people));
$somePersona = $personas->getFirst();
$somePeople = $people->getFirst();
$this->assertEquals($somePersona->cedula, $somePeople->cedula);
//Where with named bind params + order + limit
$personas = Personas::query()->where("estado=:estado:")->bind(array("estado" => "A"))->orderBy("nombres")->limit(100)->execute();
$people = People::find(array("estado=:estado:", "bind" => array("estado" => "A"), "order" => "nombres", "limit" => 100));
$this->assertEquals(count($personas), count($people));
$somePersona = $personas->getFirst();
$somePeople = $people->getFirst();
$this->assertEquals($somePersona->cedula, $somePeople->cedula);
}
示例4: _executeTestsNormal
protected function _executeTestsNormal($di)
{
$number = 0;
$robots = Robots::find();
foreach ($robots as $robot) {
$this->assertTrue(is_object($robot));
$this->assertEquals(get_class($robot), 'Robots');
$number++;
}
$robots->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_RECORDS);
foreach ($robots as $robot) {
$this->assertTrue(is_object($robot));
$this->assertEquals(get_class($robot), 'Robots');
$number++;
}
$robots->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_ARRAYS);
foreach ($robots as $robot) {
$this->assertTrue(is_array($robot));
$this->assertEquals(count($robot), 4);
$number++;
}
$robots->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS);
foreach ($robots as $robot) {
$this->assertTrue(is_object($robot));
$this->assertEquals(get_class($robot), 'stdClass');
$number++;
}
$this->assertEquals($number, 12);
$number = 0;
$people = People::find(array('limit' => 33));
foreach ($people as $person) {
$this->assertTrue(is_object($person));
$this->assertEquals(get_class($person), 'People');
$number++;
}
$people->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_RECORDS);
foreach ($people as $person) {
$this->assertTrue(is_object($person));
$this->assertEquals(get_class($person), 'People');
$number++;
}
$people->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_ARRAYS);
foreach ($people as $person) {
$this->assertTrue(is_array($person));
$number++;
}
$people->setHydrateMode(Phalcon\Mvc\Model\Resultset::HYDRATE_OBJECTS);
foreach ($people as $person) {
$this->assertTrue(is_object($person));
$this->assertEquals(get_class($person), 'stdClass');
$number++;
}
$this->assertEquals($number, 33 * 4);
}
示例5: 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);
}