Simple fix in foreignkeyfields and addded new features for pass arguments to forms via model field
This commit is contained in:
parent
ae2e94d224
commit
a57f714cd2
5 changed files with 28 additions and 9 deletions
|
|
@ -25,21 +25,22 @@ class ForeignKeyField extends IntegerField{
|
||||||
public $fields_related_model;
|
public $fields_related_model;
|
||||||
public $name_field_to_field;
|
public $name_field_to_field;
|
||||||
|
|
||||||
function __construct($related_model, $size=11, $default=0)
|
function __construct($related_model, $size=11, $default_id=0, $name_field='', $name_value='')
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->size=$size;
|
$this->size=$size;
|
||||||
$this->form='PhangoApp\PhaModels\Forms\SelectForm';
|
$this->form='PhangoApp\PhaModels\Forms\SelectModelForm';
|
||||||
$this->related_model=&$related_model;
|
$this->related_model=&$related_model;
|
||||||
$this->container_model=$this->related_model->name;
|
$this->container_model=$this->related_model->name;
|
||||||
//Fields obtained from related_model if you make a query...
|
//Fields obtained from related_model if you make a query...
|
||||||
$this->fields_related_model=array();
|
$this->fields_related_model=array();
|
||||||
//Representative field for related model...
|
//Representative field for related model...
|
||||||
$this->name_field_to_field='';
|
$this->name_field_to_field=$name_field;
|
||||||
$this->default_id=$default;
|
$this->default_id=$default_id;
|
||||||
$this->quot_open='';
|
$this->quot_open='';
|
||||||
$this->quot_close='';
|
$this->quot_close='';
|
||||||
$this->protected=0;
|
$this->protected=0;
|
||||||
|
$this->parameters=array(&$this->related_model, $name_field, $name_value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,7 +103,7 @@ class PhangoField {
|
||||||
public $form_loaded;
|
public $form_loaded;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Array for create initial parameters for form..
|
* Array for create initial extra parameters for form.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public $parameters=array();
|
public $parameters=array();
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ class BaseForm {
|
||||||
|
|
||||||
public $enctype=0;
|
public $enctype=0;
|
||||||
|
|
||||||
public function __construct($name, $value)
|
public function __construct($name, $value, $extra_parameters=array())
|
||||||
{
|
{
|
||||||
$this->label=$name;
|
$this->label=$name;
|
||||||
$this->name=$name;
|
$this->name=$name;
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class SelectModelForm extends SelectForm{
|
||||||
|
|
||||||
public $model;
|
public $model;
|
||||||
|
|
||||||
public $conditions='WHERE 1=1';
|
public $conditions=['WHERE 1=1', []];
|
||||||
|
|
||||||
public $field_value='';
|
public $field_value='';
|
||||||
|
|
||||||
|
|
@ -21,6 +21,19 @@ class SelectModelForm extends SelectForm{
|
||||||
|
|
||||||
public $raw_query=0;
|
public $raw_query=0;
|
||||||
|
|
||||||
|
public function __construct($name, $value, $model, $field_name, $field_value)
|
||||||
|
{
|
||||||
|
|
||||||
|
parent::__construct($name, $value);
|
||||||
|
|
||||||
|
$this->model=&$model;
|
||||||
|
|
||||||
|
$this->field_name=$field_name;
|
||||||
|
|
||||||
|
$this->field_value=$field_value;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function form()
|
public function form()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
@ -32,7 +45,7 @@ class SelectModelForm extends SelectForm{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$this->model->set_conditions($this->conditions);
|
$this->model->set_conditions($this->conditions[0], $this->conditions[1]);
|
||||||
|
|
||||||
$query=$this->model->select(array($this->field_name, $this->field_value), $this->raw_query);
|
$query=$this->model->select(array($this->field_name, $this->field_value), $this->raw_query);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2032,7 +2032,12 @@ class Webmodel {
|
||||||
|
|
||||||
$form_class=$component->form;
|
$form_class=$component->form;
|
||||||
|
|
||||||
$this->forms[$component_name]=new $form_class($component_name, $component->value);
|
//$this->forms[$component_name]=new $form_class($component_name, $component->value, $component->parameters);
|
||||||
|
$rc=new \ReflectionClass($form_class);
|
||||||
|
|
||||||
|
array_unshift($component->parameters, $component_name, $component->value);
|
||||||
|
|
||||||
|
$this->forms[$component_name]=$rc->newInstanceArgs($component->parameters);
|
||||||
|
|
||||||
$type_class=get_class($this->forms[$component_name]);
|
$type_class=get_class($this->forms[$component_name]);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue