AbstractView::setModel PHP Метод

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

Associate view with a model. Additionally may initialize a controller which would copy fields from the model into the View.
public setModel ( object | string $model, array | string | null $actual_fields = UNDEFINED ) : AbstractModel
$model object | string Class without "Model_" prefix or object
$actual_fields array | string | null List of fields in order to populate
Результат AbstractModel object
    public function setModel($model, $actual_fields = UNDEFINED)
    {
        parent::setModel($model);
        // Some models will want default controller to be associated
        if ($this->model->default_controller) {
            $this->controller = $this->model->setController($this->model->default_controller);
        }
        // Use our default controller if present
        if ($this->default_controller) {
            $this->controller = $this->setController($this->default_controller);
        }
        if ($this->controller) {
            if ($this->controller->hasMethod('setActualFields')) {
                $this->controller->setActualFields($actual_fields);
            }
            if ($this->controller->hasMethod('_bindView')) {
                $this->controller->_bindView();
            }
        }
        if ($this->model instanceof SQL_Model) {
            $this->dq = $this->model->_dsql();
            // compatibility
        }
        return $this->model;
    }

Usage Example

Пример #1
0
 function setModel($m)
 {
     $m = parent::setModel($m);
     if ($m instanceof filestore\Model_Image) {
         $this->initializeTemplate(null, array($this->addon . './view/thumb'));
     } else {
         $this->initializeTemplate(null, array($this->addon . './view/file'));
     }
     $this->uploader = $this->add($this->addon . '/View_Uploader');
     $this->uploader->addHook('afterUpload', $this);
 }