当前位置: 首页>>代码示例>>PHP>>正文


PHP Robots::find方法代码示例

本文整理汇总了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);
 }
开发者ID:aisuhua,项目名称:phalcon-php,代码行数:12,代码来源:CacheResultsetTest.php

示例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'));
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:19,代码来源:Model.php

示例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);
 }
开发者ID:UqiOnline,项目名称:cphalcon7,代码行数:15,代码来源:CacheResultsetTest.php

示例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();
     }
 }
开发者ID:Zhanat87,项目名称:Ariya-House-IT-test,代码行数:16,代码来源:RobotsService.php

示例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);
     }
 }
开发者ID:Jurigag,项目名称:cphalcon,代码行数:38,代码来源:ModelsSerializeTest.php

示例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());
 }
开发者ID:lisong,项目名称:cphalcon,代码行数:36,代码来源:ModelsResultsetTest.php

示例7: foreach

<?php

$robot = Robots::findFirst();
$robot->delete();
foreach (Robots::find() as $robot) {
    $robot->delete();
}
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:7,代码来源:Phalcon_Mvc_Collection-403.php

示例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);
 }
开发者ID:racklin,项目名称:cphalcon,代码行数:54,代码来源:ModelsHydrationTest.php

示例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'));
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:6,代码来源:models-cache-661.php

示例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();
}
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:24,代码来源:models-2208.php

示例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);
 }
开发者ID:boedy,项目名称:cphalcon,代码行数:17,代码来源:CacheResultsetTest.php

示例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";
}
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:18,代码来源:odm-138.php

示例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;
}
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:19,代码来源:models-976.php

示例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)));
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:6,代码来源:odm-191.php

示例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";
}
开发者ID:aodkrisda,项目名称:phalcon-code,代码行数:22,代码来源:Phalcon_Cache_Frontend_Data-8.php


注:本文中的Robots::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。