public function addRef($name, $options = array())
{
if (!$this->model) {
throw $this->exception('Must set CRUD model first');
}
if (!is_array($options)) {
throw $this->exception('Must be array');
}
// if(!$this->grid || $this->grid instanceof Dummy)return;
$s = $this->app->normalizeName($name);
if ($this->isEditing('ex_' . $s)) {
$n = $this->virtual_page->name . '_' . $s;
if ($_GET[$n]) {
$this->id = $_GET[$n];
$this->app->stickyGET($n);
}
$idfield = $this->model->table . '_' . $this->model->id_field;
if ($_GET[$idfield]) {
$this->id = $_GET[$idfield];
$this->app->stickyGET($idfield);
}
$view_class = is_null($options['view_class']) ? get_class($this) : $options['view_class'];
$subview = $this->virtual_page->getPage()->add($view_class, $options['view_options']);
$this->model->load($this->id);
$subview->setModel($options['view_model'] ? is_callable($options['view_model']) ? call_user_func($options['view_model'], $this->model) : $options['view_model'] : $this->model->ref($name), $options['fields'], $options['grid_fields'] ?: $options['extra_fields']);
return $subview;
} elseif ($this->grid instanceof Grid) {
$this->grid->addColumn('expander', 'ex_' . $s, $options['label'] ?: $s);
$this->grid->columns['ex_' . $s]['page'] = $this->virtual_page->getURL('ex_' . $s);
// unused: $idfield = $this->grid->columns['ex_'.$s]['refid'].'_'.$this->model->id_field;
}
if ($this->isEditing()) {
return;
}
}