setter and getter methods usage

hey guys …i have a question about the setter and getter method usage in yiii…Specially in case of dynamic attributes.I have a situation …I have a button in my form(Add more Button) that adds field dynamically in the form…these fields are not the part of the model.how to put validation on these fields.I shall be really thankful to you guys if someone give the solution to this problem and let me understand the usage of setter and getter methods like where to use it,how to use it??????????Please Please Help me out guys

Virtual attributes are usually used when an attribute value

  • is a result of a calculation:



public function getAge()

{

  //...

  return $currentTimestamp - $this->creationTimestamp;

}


echo $model->age;



  • is a result of a resource-intensive operation which should be delayed until it becomes absolutely necessary:



public function getMyAttribute()

{

  if ( ! isset($this->_myAttribute)) {

	$this->_myAttribute = // run expensive SQL queries or other operations here

  }

  return $this->_myAttribute;

}



If you want to validate some non-persistent attributes of your model, simply add them to the model class as regular public properties.

but the field gets added after using add more button how can i make a property public on onclik of a button

Hi

learn below url may be use full to you

http://www.yiiframework.com/doc/guide/1.1/en/form.model#declaring-validation-rules

Thanks

pravin this is not the solution cause on click of a button or onsububmit can’t make any property public

So you want to add unlimited number of fields of the same type to your model/form? A single model attribute can be used to store them as an array.

yes like a field submodule is there when i click on add more button the fields like submodule1,submodule2. gets created …how can i validate these fields

can anyone help me out

any one with the solution