I want to extract the maximum value in a certain table column called ‘order’. To do this, I use a function in a bahavior which is attached to the model.
class mybehavior extends CActiveRecordBehavior
{
public $maxColumn = 0;
public function getMaxOrder()
{
$model = $this->getOwner();
$criteria = new CDbCriteria;
$criteria->select = 'MAX(t.order) as maxColumn';
$criteria->condition = 't.business = :parm';
$criteria->params = array(
':parm' => Yii::app()->user->getState('businessID')
);
$maxmodel = $model->find($criteria);
$max = $maxmodel['maxColumn'];
return $max;
}
}
The above code does not work - the value of $maxColumn stays 0.
But if I remove ‘public $maxColumn = 0;’ from the behavior and put it in the model, then the above code works.
Any ideas how to get the code to work with $maxColumn being defined in the behavior and not in the model?