php - How to reset data mapper's virtual fields in Fat Free Framework? -


let's start example given on fff user guide. there database table:

create table products (     productid varchar(30),     description varchar(255),     supplierid varchar(30),     unitprice decimal(10,2),     quantity int,     primary key(productid) ); 

and have data mapper virtual field:

$item=new db\sql\mapper($db,'products'); $item->totalprice='unitprice*quantity'; 

let's have performed queries , used virtual field.

now remove virtual field, because don't need further requests , don't want overload data base useless calculations. possible?

the requirement remove 'property' 'object instance'.

the 'standard way' 'models' implemented in php 'framework', 'orm' etc. implement them can accessed using 'array syntax'.

another approach implement of magic methods such __unset.

i.e. when call unset($item->property); code run maintain correctly.

to flexible implement both approaches in 'base models'

this fff have done.

see: classes: lib/magic.php , lib/base.php gory details of how done.

taken source magic.php...

/** *   alias offsetunset() *   @return null *   @param $key string **/ function __unset($key) {     $this->offsetunset($key); }   /** *   convenience method removing property value *   @return null *   @param $key string **/ function offsetunset($key) {     if (base::instance()->visible($this,$key))         unset($this->$key);     else         $this->clear($key); } 

Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -