Cdbcriteria Variable Problem In Behavior

I just made a behavior for NextAvailableId which is for Auto Incrementing the primary key, due to some complexity of the project, we cannot use auto increment in the table itself, now for getting next available id i have created this function




        public function getNextAvailableId()

        {

            $criteria=new CDbCriteria;

            $criteria->select='IFNULL(max(id),0)+1 AS _maxAttr';

            $criteria->params = array(

                ':attribute' => $this->attribute,

                );

            $myrow = $this->getOwner()->model()->find($criteria);

            return ($myrow['_maxAttr']);

        }



Since it is a CDbCriteria it asks to declare _maxAttr in the model, now to execute i have to add this to every model file, which creates a lot of repetition i am trying to avoid, another way is i can add the variable to the parent Model file and extend each file with it, but that destroys the purpose of the Behavior to run independently, adding the variable to the Behavior allows it to run but the above function returns nothing. Please advice how to declare the variable in such a way that behavior file can run independently.

Operating System: Windows Xp

Web server: WAMP (Apache)

Browser Type: IE 9.0

Yii version: 1.1

I’ve some problems in CDbCriteria so that it would be easy if you will resolve my issue… Thanks I’ll pm you.