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.
Afficher le fichier
Open project: atk4/atk4
Méthodes publiques
Свойство |
Type |
Description |
|
$expr |
|
|
|
Méthodes publiques
Method Details
calculated()
public méthode
editable()
public méthode
specify DSQL, String or function($model, $dsql, $this_field)
public set ( $expr = null ) |
updateInsertQuery()
public méthode
updateModifyQuery()
public méthode
updateSelectQuery()
public méthode
Property Details