PHP Class Field_Expression, atk4
Field_Expression implements ability to specify expressions inside your
SQL_Model and have them appear as a read-only fields.
Use:
$model->addExpression('age','year(now())-year(birthdate)');
Below example achieves the same,but it prefixes age with proper table name
$model->addExpression('age',
'year(now())-year('.$model->getElement('adatege').')');
$model->addExpression('row_counter',$this->db->dsql()->useExpr('@x := @x+1');
using custom controller to format field
$myctl=$this->add('Controller_MiscMySQL');
$model->addExpression('date_formatted',array($myctl,'dateExpr1'));
or
or by using closure and extra argument
$myctl=$this->add('Controller_MiscMySQL');
$model->addExpression('date_formatted',
function($model,$query) uses $myctl {
return $myctl->dateExpr2($query,'date_raw');
});
NOTE: MiscMySQL is fictional controller.
Mostra file
Open project: atk4/atk4
Public Properties
Property |
Type |
Description |
|
$expr |
|
|
|
Public Methods
Method Details
calculated()
public method
specify DSQL, String or function($model, $dsql, $this_field)
public set ( $expr = null ) |
updateInsertQuery()
public method
updateModifyQuery()
public method
updateSelectQuery()
public method
Property Details