Model Validation , Array Component

Hi everyone , i’m here with one problem :

i have an array in model




public prop = array(

1 => 'Value1',

2 => 'Value2'

)

and my code will generate rules for this array , such as:


array('prop[1]','length','min' => '0'),

array('prop[2]','length','min' => '0')

Error :

Question : Why validator can’t see this value ? or there’s no support for array ?

any solutions to solve ?

Thanks. <_<

Sorry for my english

Try this.




public $prop = array(

1 => 'Value1',

2 => 'Value2'

)



If it doesn’t work try this:




public $prop = array(

'1' => 'Value1',

'2' => 'Value2'

)



and




array('prop["1"]','length','min' => '0'),

array('prop["2"]','length','min' => '0')



same error … :-X

found solution in CActiveRecord source code , and added this part of code to my model :




	public function getVarNameFromString($name){

		$varName = '';

		for($i=0;$i<=strlen($name);$i++){			

			if($name[$i] == '[')

				break;

			$varName .= $name[$i];

		}

		return $varName;

	}


	public function __get($name)

	{	

		if(property_exists($this,$this->getVarNameFromString($name)))

			return $this->{$name};

		else

			return parent::__get($name);

	}