本文整理汇总了PHP中Robots::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Robots::find方法的具体用法?PHP Robots::find怎么用?PHP Robots::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Robots
的用法示例。
在下文中一共展示了Robots::find方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testCacheResultsetBinding
public function testCacheResultsetBinding()
{
$cache = $this->_getCache();
$initialId = 0;
$finalId = 4;
$cache->save('test-resultset', Robots::find(array('conditions' => 'id > :id1: and id < :id2:', 'bind' => array('id1' => $initialId, 'id2' => $finalId), 'order' => 'id')));
$this->assertTrue(file_exists(__DIR__ . '/cache/test-resultset'));
$robots = $cache->get('test-resultset');
$this->assertEquals(get_class($robots), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
$this->assertEquals(count($robots), 3);
$this->assertEquals($robots->count(), 3);
}
示例2: testSelectBasic
/**
* Tests an image tag with a bare minimum of information passed
*
* @author Nikos Dimopoulos <nikos@niden.net>
* @since 2012-09-09
*/
public function testSelectBasic()
{
// Populate the table
// Empty the relationship table first
$this->emptyTable('robots_parts');
$this->populateTable('robots');
$this->populateTable('robots_parts');
$robots = \Robots::find();
$params = array('some_name', $robots, 'using' => array('id', 'name'));
$expected = '<select id="some_name" name="some_name">' . PHP_EOL . chr(9) . '<option value="1">Robotina</option>' . PHP_EOL . chr(9) . '<option value="2">Astro Boy</option>' . PHP_EOL . chr(9) . '<option value="3">Terminator</option>' . PHP_EOL . '</select>';
$actual = PhTag::select($params);
$this->assertEquals($expected, $actual, sprintf($this->message, 'select basic'));
}
示例3: testCacheResultsetNormal
public function testCacheResultsetNormal()
{
require 'unit-tests/config.db.php';
if (empty($configMysql)) {
$this->markTestSkipped('Test skipped');
return;
}
$cache = $this->_getCache();
$cache->save('test-resultset', Robots::find(array('order' => 'id')));
$this->assertTrue(file_exists('unit-tests/cache/test-resultset'));
$robots = $cache->get('test-resultset');
$this->assertEquals(get_class($robots), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
$this->assertEquals(count($robots), 3);
$this->assertEquals($robots->count(), 3);
}
示例4: findByName
public static function findByName($name)
{
$response = new Response();
if (!$name) {
$response->status = $response::STATUS_BAD_REQUEST;
$response->addError('параметр "name" не может быть пустым');
return $response->toArray();
}
try {
$response->data = Robots::find(['conditions' => 'name LIKE :name:', 'bind' => ['name' => '%' . $name . '%']])->toArray();
} catch (Exception $e) {
$response->setException($e);
} finally {
return $response->toArray();
}
}
示例5: 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);
}
}
示例6: testResultsetAppendIterator
public function testResultsetAppendIterator()
{
if (!$this->_prepareTestMysql()) {
$this->markTestSkipped("Skipped");
return;
}
// see http://php.net/manual/en/appenditerator.construct.php
$iterator = new \AppendIterator();
$robots_first = Robots::find(array('limit' => 2));
$robots_second = Robots::find(array('limit' => 1, 'offset' => 2));
$robots_first_0 = $robots_first[0];
$robots_first_1 = $robots_first[1];
$robots_second_0 = $robots_second[0];
$iterator->append($robots_first);
$iterator->append($robots_second);
$iterator->rewind();
$this->assertTrue($iterator->valid());
$this->assertEquals($iterator->key(), 0);
$this->assertEquals($iterator->getIteratorIndex(), 0);
$this->assertEquals(get_class($iterator->current()), 'Robots');
$this->assertEquals($robots_first_0->name, $iterator->current()->name);
$iterator->next();
$this->assertTrue($iterator->valid());
$this->assertEquals($iterator->key(), 1);
$this->assertEquals($iterator->getIteratorIndex(), 0);
$this->assertEquals(get_class($iterator->current()), 'Robots');
$this->assertEquals($robots_first_1->name, $iterator->current()->name);
$iterator->next();
$this->assertTrue($iterator->valid());
$this->assertEquals($iterator->key(), 0);
$this->assertEquals($iterator->getIteratorIndex(), 1);
$this->assertEquals(get_class($iterator->current()), 'Robots');
$this->assertEquals($robots_second_0->name, $iterator->current()->name);
$iterator->next();
$this->assertFalse($iterator->valid());
}
示例7: foreach
<?php
$robot = Robots::findFirst();
$robot->delete();
foreach (Robots::find() as $robot) {
$robot->delete();
}
示例8: _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);
}
示例9: array
<?php
$robots = Robots::find('id < 1000');
$robots = Robots::find('id > 100 AND type = "A"');
$robots = Robots::find('(id > 100 AND type = "A") AND id < 2000');
$robots = Robots::find(array('(id > ?0 AND type = "A") AND id < ?1', 'bind' => array(100, 2000), 'order' => 'type'));
示例10: TxManager
<?php
use Phalcon\Mvc\Model\Transaction\Manager as TxManager, Phalcon\Mvc\Model\Transaction\Failed as TxFailed;
try {
//Create a transaction manager
$manager = new TxManager();
//Request a transaction
$transaction = $manager->get();
//Get the robots will be deleted
foreach (Robots::find("type = 'mechanical'") as $robot) {
$robot->setTransaction($transaction);
if ($robot->delete() == false) {
//Something goes wrong, we should to rollback the transaction
foreach ($robot->getMessages() as $message) {
$transaction->rollback($message->getMessage());
}
}
}
//Everything goes fine, let's commit the transaction
$transaction->commit();
echo "Robots were deleted successfully!";
} catch (TxFailed $e) {
echo "Failed, reason: ", $e->getMessage();
}
示例11: testCacheResultsetBinding
public function testCacheResultsetBinding()
{
require 'unit-tests/config.db.php';
if (empty($configMysql)) {
$this->markTestSkipped('Test skipped');
return;
}
$cache = $this->_getCache();
$initialId = 0;
$finalId = 4;
$cache->save('test-resultset', Robots::find(array('conditions' => 'id > :id1: and id < :id2:', 'bind' => array('id1' => $initialId, 'id2' => $finalId), 'order' => 'id')));
$this->assertTrue(file_exists('unit-tests/cache/test-resultset'));
$robots = $cache->get('test-resultset');
$this->assertEquals(get_class($robots), 'Phalcon\\Mvc\\Model\\Resultset\\Simple');
$this->assertEquals(count($robots), 3);
$this->assertEquals($robots->count(), 3);
}
示例12: 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 mechanical robots ordered by name upward
$robots = Robots::find(array(array("type" => "mechanical"), "sort" => array("name" => 1)));
foreach ($robots as $robot) {
echo $robot->name, "\n";
}
// Get first 100 mechanical robots ordered by name
$robots = Robots::find(array(array("type" => "mechanical"), "sort" => array("name" => 1), "limit" => 100));
foreach ($robots as $robot) {
echo $robot->name, "\n";
}
示例13:
<?php
use Phalcon\Mvc\Model\Resultset;
$robots = Robots::find();
//Return every robot as an array
$robots->setHydrateMode(Resultset::HYDRATE_ARRAYS);
foreach ($robots as $robot) {
echo $robot['year'], PHP_EOL;
}
//Return every robot as an stdClass
$robots->setHydrateMode(Resultset::HYDRATE_OBJECTS);
foreach ($robots as $robot) {
echo $robot->year, PHP_EOL;
}
//Return every robot as a Robots instance
$robots->setHydrateMode(Resultset::HYDRATE_RECORDS);
foreach ($robots as $robot) {
echo $robot->year, PHP_EOL;
}
示例14: array
<?php
// First robot where type = "mechanical" and year = "1999"
$robot = Robots::findFirst(array("type" => "mechanical", "year" => "1999"));
// All virtual robots ordered by name downward
$robots = Robots::find(array("conditions" => array("type" => "virtual"), "sort" => array("name" => -1)));
示例15: array
<?php
// Cache the files for 2 days using a Data frontend
$frontCache = new Phalcon\Cache\Frontend\Data(array("lifetime" => 172800));
// Create the component that will cache "Data" to a "File" backend
// Set the cache file directory - important to keep the "/" at the end of
// of the value for the folder
$cache = new Phalcon\Cache\Backend\File($frontCache, array("cacheDir" => "../app/cache/"));
// Try to get cached records
$cacheKey = 'robots_order_id.cache';
$robots = $cache->get($cacheKey);
if ($robots === null) {
// $robots is null due to cache expiration or data does not exist
// Make the database call and populate the variable
$robots = Robots::find(array("order" => "id"));
// Store it in the cache
$cache->save($cacheKey, $robots);
}
// Use $robots :)
foreach ($robots as $robot) {
echo $robot->name, "\n";
}