setModel() public method

Associate model with object.
public setModel ( string | object $model ) : AbstractModel
$model string | object Class or instance of model
return AbstractModel Newly added Model
Ejemplo n.º 1
0
 /** Associate view with a model. Different models may behave differently. */
 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 Model_Table) {
         $this->dq = $this->model->_dsql();
     }
     // compatibility
     return $this->model;
 }
Ejemplo n.º 2
0
 /**
  * Set model
  *
  * @param Model|string $model
  * @param string|bool $display_field
  *
  * @return Model|$this
  */
 public function setModel($model, $display_field = null)
 {
     if ($model instanceof Model) {
         return AbstractObject::setModel($model);
     }
     $this->model_name = is_string($model) ? $model : get_class($model);
     $this->model_name = (string) $this->app->normalizeClassName($this->model_name, 'Model');
     if ($display_field) {
         $this->display_field = (string) $display_field;
     }
     if ($display_field !== false) {
         $this->owner->addExpression($this->getDereferenced())->set(array($this, 'calculateSubQuery'))->caption((string) $this->caption());
     }
     $this->system(true);
     $this->editable(true);
     $this->visible(false);
     return $this;
 }