/**
  * Find column
  * @param string $column column name
  * @param mixed $condition
  * @param array $params
  * @return array column values
  */
 public function findColumn($column, $condition = '', $params = array())
 {
     $criteria = $this->owner->getCommandBuilder()->createCriteria($condition, $params);
     $criteria->select = $column;
     $this->owner->applyScopes($criteria);
     $command = $this->owner->getCommandBuilder()->createFindCommand($this->owner->getTableSchema(), $criteria);
     if (empty($criteria->with)) {
         return $command->queryColumn();
     } else {
         $finder = new CActiveFinder($this->owner, $criteria->with);
         $results = $finder->query($criteria, true);
         $data = array();
         foreach ($results as $result) {
             $data[] = $result[$column];
         }
         return $data;
     }
 }
示例#2
0
 protected function query($criteria, $all = false)
 {
     $this->beforeFind();
     $this->applyScopes($criteria);
     if (empty($criteria->with)) {
         if (!$all) {
             $criteria->limit = 1;
         }
         $command = $this->getCommandBuilder()->createFindCommand($this->getTableSchema(), $criteria);
         return $all ? $this->populateRecords($command->queryAll(), true, $criteria->index) : $this->populateRecord($command->queryRow());
     } else {
         $finder = new CActiveFinder($this, $criteria->with);
         return $finder->query($criteria, $all);
     }
 }