本文整理汇总了PHP中Propel\Runtime\ActiveQuery\ModelCriteria::orderBy方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelCriteria::orderBy方法的具体用法?PHP ModelCriteria::orderBy怎么用?PHP ModelCriteria::orderBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Runtime\ActiveQuery\ModelCriteria
的用法示例。
在下文中一共展示了ModelCriteria::orderBy方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testFindOneWithUsingInstancePool
public function testFindOneWithUsingInstancePool()
{
BookstoreDataPopulator::populate();
// instance pool contains all objects by default, since they were just populated
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->setFormatter(ModelCriteria::FORMAT_ON_DEMAND);
$c->orderBy('Propel\\Tests\\Bookstore\\Book.Title');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->with('Author');
$c->join('Propel\\Tests\\Bookstore\\Book.Publisher');
$c->with('Publisher');
$this->assertCorrectHydration1($c, 'with instance pool');
}
示例2: testFindOne
public function testFindOne()
{
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->where('b.Title = ?', 'foo');
$book = $c->findOne();
$this->assertNull($book, 'findOne() returns null when the query returns no result');
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
$c->orderBy('b.Title');
$book = $c->findOne();
$this->assertTrue($book instanceof Book, 'findOne() returns a Model object by default');
$this->assertEquals('Don Juan', $book->getTitle(), 'find() returns the model objects matching the query');
}
示例3: testFindPksSimpleKey
public function testFindPksSimpleKey()
{
BookstoreDataPopulator::depopulate();
BookstoreDataPopulator::populate();
BookTableMap::clearInstancePool();
// prepare the test data
$c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
$c->orderBy('Book.Id', 'desc');
$testBooks = $c->find();
$testBook1 = $testBooks->pop();
$testBook2 = $testBooks->pop();
$q = new BookQuery();
$books = $q->findPks(array($testBook1->getId(), $testBook2->getId()));
$this->assertEquals(array($testBook1, $testBook2), $books->getData(), 'BaseQuery overrides findPks() to make it faster');
}
示例4: testFindOneWithoutUsingInstancePool
public function testFindOneWithoutUsingInstancePool()
{
BookstoreDataPopulator::populate();
Propel::disableInstancePooling();
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->orderBy('Propel\\Tests\\Bookstore\\Book.Title');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->with('Author');
$c->join('Propel\\Tests\\Bookstore\\Book.Publisher');
$c->with('Publisher');
$this->assertCorrectHydration1($c, 'without instance pool');
Propel::enableInstancePooling();
}
示例5: testSelectArrayWithColumn
public function testSelectArrayWithColumn()
{
BookstoreDataPopulator::depopulate($this->con);
BookstoreDataPopulator::populate($this->con);
$c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
$c->join('Propel\\Tests\\Bookstore\\Book.Author');
$c->withColumn('LOWER(Propel\\Tests\\Bookstore\\Book.Title)', 'LowercaseTitle');
$c->select(array('LowercaseTitle', 'Propel\\Tests\\Bookstore\\Book.Title'));
$c->orderBy('Propel\\Tests\\Bookstore\\Book.Title');
$rows = $c->find($this->con);
$expectedSQL = $this->getSql('SELECT LOWER(book.TITLE) AS LowercaseTitle, book.TITLE AS "Propel\\Tests\\Bookstore\\Book.Title" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) ORDER BY book.TITLE ASC');
$this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
$expectedRows = array(array('LowercaseTitle' => 'don juan', 'Propel\\Tests\\Bookstore\\Book.Title' => 'Don Juan'), array('LowercaseTitle' => 'harry potter and the order of the phoenix', 'Propel\\Tests\\Bookstore\\Book.Title' => 'Harry Potter and the Order of the Phoenix'), array('LowercaseTitle' => 'quicksilver', 'Propel\\Tests\\Bookstore\\Book.Title' => 'Quicksilver'), array('LowercaseTitle' => 'the tin drum', 'Propel\\Tests\\Bookstore\\Book.Title' => 'The Tin Drum'));
$this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
}
示例6: mapOptions
/**
* Maps options like limit, offset, order
*
* @param ModelCriteria $query
* @param array $options
*
* @throws FileNotFoundException
*/
public function mapOptions(ModelCriteria $query, $options = array())
{
if (isset($options['limit'])) {
$query->limit($options['limit']);
}
if (isset($options['offset'])) {
$query->offset($options['offset']);
}
if (isset($options['order']) && is_array($options['order'])) {
foreach ($options['order'] as $field => $direction) {
$fieldName = ucfirst($field);
$tableMap = $this->tableMap;
if (false !== ($pos = strpos($field, '.'))) {
$relationName = ucfirst(substr($field, 0, $pos));
$fieldName = ucfirst(substr($field, $pos + 1));
if (!($relation = $this->tableMap->getRelation($relationName))) {
throw new FileNotFoundException(sprintf('Relation `%s` in object `%s` not found', $relationName, $this->getObjectKey()));
}
$tableMap = $relation->getForeignTable();
}
if ($tableMap->hasColumnByPhpName(ucfirst($fieldName))) {
$column = $this->tableMap->getColumnByPhpName(ucfirst($fieldName));
$query->orderBy($column->getName(), $direction);
}
}
}
}