Non-static variable between beforeFind afterFind

Hi,

I programmed a multilanguage behavior. It has a setLocalize method with this signature:


setLocalize($languageCode, $loadAllLocale, $copyIntoVirtualAttributes)

, and it has 3 private properties:


$_languageCode, $_loadAllLocale, $_copyIntoVirtualAttributes

. If they are not setted, then they are setted in beforeFind, by beforeFind call


setLocalize($defaultLanguageCode, false, false);

. In afterFind, I want to set virtual attributes if $_copyIntoVirtualAttributes is true, but


$_languageCode, $_loadAllLocale, $_copyIntoVirtualAttributes

is null. Can I read setted virtual attributes from afterFind?

And a try it:


Content::model()->setLocalize("en_US", false, false)->with(array(

  'post' => array(

    'scopes' => array(

      setLocalize("en_US", true, true),

    ),

  ),

))->findAll()


<?php

interface IPersistentBehavior {

    public function getPersistentVariable();

}

?>


<?php

class XActiveRecord extends CActiveRecord {


    /**

     * Creates an active record with the given attributes.

     * This method is internally used by the find methods.

     * @param array $attributes attribute values (column name=>column value)

     * @param boolean $callAfterFind whether to call {@link afterFind} after the record is populated.

     * @return CActiveRecord the newly created active record. The class of the object is the same as the model class.

     * Null is returned if the input data is false.

     */

    public function populateRecord($attributes, $callAfterFind = true) {

        if ($attributes !== false) {

            $record = $this->instantiate($attributes);

            $recordBehaviors = $record->behaviors();


            $behaviors = $this->getBehaviors();

            foreach ($behaviors as $name => $behavior) {

                if (isset($recordBehaviors[$name]) && $behavior instanceof IPersistentBehavior) {

                    $oldConfig = $this->getBehavior($name)->getPersistentVariable();

                    $recordBehaviors[$name] = CMap::mergeArray($recordBehaviors[$name], $oldConfig);

                }

            }


            $record->setScenario('update');

            $record->init();

            $md = $record->getMetaData();

            foreach ($attributes as $name => $value) {

                if (property_exists($record, $name))

                    $record->$name = $value;

                else if (isset($md->columns[$name]))

                    $record->_attributes[$name] = $value;

            }

            $record->_pk = $record->getPrimaryKey();

            $record->attachBehaviors($recordBehaviors);

            if ($callAfterFind)

                $record->afterFind();

            return $record;

        }

        else

            return null;

    }

}

?>


<?php

class XLocalizerBehavior extends CActiveRecordBehavior implements IPersistentBehavior {


    public $langId = null;

    public $loadAllLocale = null;

    public $copyVirtualAttributes = null;


    public function getPersistentVariable() {

        return array(

            'langId' => $this->langId,

            'loadAllLocale' => $this->loadAllLocale,

            'copyVirtualAttributes' => $this->copyVirtualAttributes

        );

    }

}

?>