Controller_Data_Array::setSource PHP Метод

setSource() публичный Метод

public setSource ( $model, $table )
    public function setSource($model, $table)
    {
        if (!is_array($table)) {
            throw $this->exception('Wrong type: expected array')->addMoreInfo('source', $table);
        }
        if (!$model->hasMethod('push')) {
            $model->addMethod('push', $this);
        }
        // convert single dimension arrays
        reset($table);
        list(, $firstrow) = each($table);
        if (!is_array($firstrow)) {
            // assuming that this array needs to be converted
            foreach ($table as $key => &$name) {
                $name = array($model->id_field => $key, $model->title_field => $name);
            }
            return parent::setSource($model, $table);
        }
        $data = array();
        foreach ($table as $key => $row) {
            $id = isset($row[$model->id_field]) ? $row[$model->id_field] : $key;
            $data[$id] = $row;
        }
        return parent::setSource($model, $data);
    }

Usage Example

Пример #1
0
 function setSource(\Model $m, $data)
 {
     // Calculate sub-child count
     foreach ($data as &$row) {
         $row[$this->field . '_cnt'] = count($row[$this->field]);
     }
     parent::setSource($m, $data);
 }
All Usage Examples Of Controller_Data_Array::setSource