Controller_Data::setSource PHP Метод

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

All necessary data must be stored in $model->_table[$this->short_name] to avoid conflicts between different controllers and to allow user to use one controller with multiple models.
public setSource ( $model, $data )
    public function setSource($model, $data)
    {
        $model->_table[$this->short_name] = $data;
        return $this;
    }

Usage Example

Пример #1
0
 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);
 }
All Usage Examples Of Controller_Data::setSource