本文整理汇总了PHP中Robots::findFirst方法的典型用法代码示例。如果您正苦于以下问题:PHP Robots::findFirst方法的具体用法?PHP Robots::findFirst怎么用?PHP Robots::findFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Robots
的用法示例。
在下文中一共展示了Robots::findFirst方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSerialize
public function testSerialize()
{
$this->_prepareDI();
$robot = Robots::findFirst();
$serialized = serialize($robot);
$robot = unserialize($serialized);
$this->assertTrue($robot->save());
}
示例2: testSerialize
public function testSerialize()
{
require 'unit-tests/config.db.php';
if (empty($configMysql)) {
$this->markTestSkipped('Test skipped');
return;
}
$this->_prepareDI();
$robot = Robots::findFirst();
$serialized = serialize($robot);
$robot = unserialize($serialized);
$this->assertTrue($robot->save());
}
示例3: update
public static function update($id, $data)
{
$response = new Response();
try {
$data = json_decode($data, true);
/** @var Robots $robot */
$robot = Robots::findFirst($id);
$robot->setAttributes($data);
$response->data = $robot->update();
} catch (Exception $e) {
$response->setException($e);
} finally {
return $response->toArray();
}
}
示例4: testJsonSerialize
public function testJsonSerialize()
{
require 'unit-tests/config.db.php';
if (empty($configMysql)) {
$this->markTestSkipped('Test skipped');
return;
}
$di = $this->_getDI();
// Single model object json serialization
$robot = Robots::findFirst();
$json = json_encode($robot);
$this->assertTrue(is_string($json));
$this->assertTrue(strlen($json) > 10);
// make sure result is not "{ }"
$array = json_decode($json, true);
$this->assertEquals($robot->toArray(), $array);
// Result-set serialization
$robots = Robots::find();
$json = json_encode($robots);
$this->assertTrue(is_string($json));
$this->assertTrue(strlen($json) > 50);
// make sure result is not "{ }"
$array = json_decode($json, true);
$this->assertEquals($robots->toArray(), $array);
// Single row serialization
$result = $di->get('modelsManager')->executeQuery('SELECT id FROM Robots LIMIT 1');
$this->assertEquals(get_class($result), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
foreach ($result as $row) {
$this->assertEquals(get_class($row), 'Phalcon\\Mvc\\Model\\Row');
$this->assertEquals($row->id, $robot->id);
$json = json_encode($row);
$this->assertTrue(is_string($json));
$this->assertTrue(strlen($json) > 5);
// make sure result is not "{ }"
$array = json_decode($json, true);
$this->assertEquals($row->toArray(), $array);
}
}
示例5:
<?php
//What's the first robot in robots table?
$robot = Robots::findFirst();
echo "The robot name is ", $robot->name;
//What's the first mechanical robot in robots table?
$robot = Robots::findFirst("type='mechanical'");
echo "The first mechanical robot name is ", $robot->name;
//Get first virtual robot ordered by name
$robot = Robots::findFirst(array("type='virtual'", "order" => "name"));
echo "The first virtual robot name is ", $robot->name;
示例6: _executeTestsNormal
public function _executeTestsNormal($di)
{
//Normal foreign keys
$robotsParts = new RobotsParts();
$robotsParts->robots_id = 1;
$robotsParts->parts_id = 100;
$this->assertFalse($robotsParts->save());
$messages = array(0 => Phalcon\Mvc\Model\Message::__set_state(array('_type' => 'ConstraintViolation', '_message' => 'Value of field "parts_id" does not exist on referenced table', '_field' => 'parts_id')));
$this->assertEquals($robotsParts->getMessages(), $messages);
$robotsParts->robots_id = 100;
$robotsParts->parts_id = 1;
$this->assertFalse($robotsParts->save());
$messages = array(0 => Phalcon\Mvc\Model\Message::__set_state(array('_type' => 'ConstraintViolation', '_message' => 'The robot code does not exist', '_field' => 'robots_id')));
$this->assertEquals($robotsParts->getMessages(), $messages);
//Reverse foreign keys
$robot = Robots::findFirst();
$this->assertNotEquals($robot, false);
$this->assertFalse($robot->delete());
$messages = array(0 => Phalcon\Mvc\Model\Message::__set_state(array('_type' => 'ConstraintViolation', '_message' => 'Record is referenced by model RobotsParts', '_field' => 'id')));
$this->assertEquals($robot->getMessages(), $messages);
$part = Parts::findFirst();
$this->assertNotEquals($part, false);
$this->assertFalse($part->delete());
$messages = array(0 => Phalcon\Mvc\Model\Message::__set_state(array('_type' => 'ConstraintViolation', '_message' => 'Parts cannot be deleted because is referenced by a Robot', '_field' => 'id')));
$this->assertEquals($part->getMessages(), $messages);
}
示例7:
<?php
$robot = Robots::findFirst("id=100");
$robot->delete();
foreach (Robots::find("type = 'mechanical'") as $robot) {
$robot->delete();
}
示例8:
<?php
// What's the first robot in robots collection?
$robot = Robots::findFirst();
echo "The robot name is ", $robot->name, "\n";
// What's the first mechanical robot in robots collection?
$robot = Robots::findFirst(array(array("type" => "mechanical")));
echo "The first mechanical robot name is ", $robot->name, "\n";
示例9: queryAction
public function queryAction()
{
$robot = Robots::findFirst();
$this->view->setVar("name", $robot->name);
}
示例10: issue1801
protected function issue1801($di)
{
Phalcon\Mvc\Model::setup(array('columnRenaming' => false));
$robot = Robots::findFirst(1);
$di->get('modelsMetadata')->reset();
$robot = Robots::findFirst(1);
$this->assertTrue(true);
}
示例11: testMetadataRedis
public function testMetadataRedis()
{
require __DIR__ . '/config.db.php';
if (empty($configMysql)) {
$this->markTestSkipped('Test skipped');
return;
}
if (!extension_loaded('redis')) {
$this->markTestSkipped('Warning: redis extension is not loaded');
return;
}
$di = $this->_getDI();
$di->set('modelsMetadata', function () {
return new Phalcon\Mvc\Model\Metadata\Redis(array("host" => "localhost", "port" => "6379"));
});
$metaData = $di->getShared('modelsMetadata');
$metaData->reset();
$this->assertTrue($metaData->isEmpty());
Robots::findFirst();
$this->assertEquals($metaData->read("meta-robots-robots"), $this->_data['meta-robots-robots']);
$this->assertEquals($metaData->read("map-robots"), $this->_data['map-robots']);
$this->assertFalse($metaData->isEmpty());
$metaData->reset();
$this->assertTrue($metaData->isEmpty());
Robots::findFirst();
}
示例12: _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';
//.........这里部分代码省略.........
示例13: foreach
<?php
$robot = Robots::findFirst(11);
if ($robot != false) {
if ($robot->delete() == false) {
echo "Sorry, we can't delete the robot right now: \n";
foreach ($robot->getMessages() as $message) {
echo $message, "\n";
}
} else {
echo "The robot was deleted successfully!";
}
}
示例14: count
<?php
//How many robots are there?
$robots = Robots::find();
echo "There are ", count($robots), "\n";
//How many mechanical robots are there?
$robots = Robots::find(array(array("type" => "mechanical")));
echo "There are ", count($robots), "\n";
//Get and print virtual robots ordered by name
$robots = Robots::findFirst(array(array("type" => "virtual"), "order" => array("name" => 1)));
foreach ($robots as $robot) {
echo $robot->name, "\n";
}
//Get first 100 virtual robots ordered by name
$robots = Robots::find(array(array("type" => "virtual"), "order" => array("name" => 1), "limit" => 100));
foreach ($robots as $robot) {
echo $robot->name, "\n";
}
示例15:
<?php
$robot = Robots::findFirst(2);
// Robots model has a 1-n (hasMany)
// relationship to RobotsParts, then
$robotsParts = RobotsParts::find("robots_id = '" . $robot->id . "'");
// Only parts that match conditions
$robotsParts = RobotsParts::find("robots_id = '" . $robot->id . "' AND created_at = '2012-03-15'");
$robotPart = RobotsParts::findFirst(1);
// RobotsParts model has a n-1 (belongsTo)
// relationship to RobotsParts then
$robot = Robots::findFirst("id = '" . $robotPart->robots_id . "'");