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.
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